Deploy Github Pages With GPG Signing

简介: This article is also posted on my blog, feel free refer to it for the latest revisions: [Deploy Github Pages With GPG Signing](https://blog.timerring.com/posts/deploy-github-pages-with-gpg-signing)

This article is also posted on my blog, feel free refer to it for the latest revisions: Deploy Github Pages With GPG Signing

I have been busy migrating my blog this week. Coincidentally, I learned that there may be cases of commit forgery on GitHub. Therefore, for security reasons, I added a GPG signature. However, when deploying Hugo, I encountered many problems regarding whether GPG signatures can also be used. Fortunately, I finally solved them.

If you don't know what GPG is, you can read GPG 101.

How to Deploy Github Pages With Gpg Signing and Verify

There are two main ways to deploy:

  1. Push all source files to GitHub directly, then use the relevant action to complete the entire deployment process.
  2. Isolate the blog source files from the built files, push the source files to the private repository of GitHub each time, and then set up the relevant workflow in the private repository to push to the public static repository.

To ensure greater security, I chose the second method, deploying Hugo in the workflow of GitHub Pages, and using the actions-gh-pages action. However, due to various reasons, the author of this action does not want to add the GPG signature feature. Therefore, we have to solve the problem ourselves.

Import GPG Key

First, I found a workflow for importing GPG keys on GitHub. After reading the documentation, my own workflow is as follows:

- name: Import GPG key # import the gpg key to the github action
  uses: crazy-max/ghaction-import-gpg@v6 # repository https://github.com/crazy-max/ghaction-import-gpg
  with: # I use the subkey to sign the commit, if you use the primary key, you can refer to his repository docs.
      gpg_private_key: ${
   {
    secrets.GPG_PRIVATE_KEY }} # the secret gpg subkey
      passphrase: ${
   {
    secrets.PASSPHRASE }} # the passphrase of the gpg subkey
      git_user_signingkey: true
      git_commit_gpgsign: true
      fingerprint: ${
   {
    secrets.FINGERPRINT }} # the fingerprint of the public subkey you use

If you only use the primary secret key of GPG, you do not need to add the fingerprint, and I generated a dedicated subkey for signing for security reasons. Therefore, you need to specify the fingerprint of the public key of the subkey. Note that the fingerprint should be entered without spaces; otherwise, it will report an error 67108933 Not implemented <GPG Agent>. I added this note to the corresponding issue.

Don't forget to fill in the corresponding secret variables and values in the repository.

Deploy

Since the author does not plan to add GPG signature, we need to clone the project and modify it ourselves. Usually, the -S option is used in the commit to specify the use of GPG signature. Therefore, I found the corresponding function in the commit and added the corresponding -S option.

Note that the modified workflow you created cannot be used directly. The author's instructions are as follows:

This action and my other actions do not provide the branch execution. I add the lib/index.js for only each release commit. After releasing, I delete it.

Therefore, we still need to publish a version ourselves. Run ./release.sh directly in the project, and publish the version you wrote. After that, you can reference your version in the workflow, and my workflow is as follows:

- name: Deploy Web
  uses: timerring/actions-gh-pages@v5.0.0 # this is adjusted action from peaceiris/actions-gh-pages, you can use it directly.
  with:
      personal_token: ${
   {
    secrets.PERSONAL_TOKEN }} # the personal token of the github action
      external_repository: your_username/your_repository # your target repository
      publish_branch: main # the branch you want to deploy
      publish_dir: ./public # the directory you want to deploy
      user_name: ${
   {
    secrets.USER_NAME }} # the name of the github action
      user_email: ${
   {
    secrets.USER_EMAIL }} # the email of the github action # ATTENTION: please add your github verified email
      commit_message: ${
   {
    github.event.head_commit.message }}

Note that please ensure that you add the email verified by GitHub; otherwise, the default parameter ${process.env.GITHUB_ACTOR}@users.noreply.github.com will only generate USERNAME@users.noreply.github.com, not ID+USERNAME@users.noreply.github.com. This is a historical issue with GitHub, details can be found here. However, your private key does not contain this UUID, so it cannot be verified by GPG. (Even if you add this UID to the keys, since the user email has not been verified by GitHub, it will only display unverified in the end.)

In short, if your GitHub account was created after July 18, 2017, then your GitHub email address is ID+USERNAME@users.noreply.github.com, not the default USERNAME@users.noreply.github.com. In this case, you need to specify the user_email parameter and fill in the email address you have verified.

Finally, after pushing to the blogsource repository, the workflow will automatically deploy to the blog repository, and the commit will be signed with GPG and display verified!

You can check my result here, every commit pushed from the blogsource repository will be signed with GPG and display verified.

Appendix

If you also need my hugo deployment method, you can directly use the action version I modified and released, repository address timerring/actions-gh-pages, refer to my complete workflow yaml, and don't forget to fill in the corresponding secret variables and values:

name: deploy

on:
    push:
        branches:
            - main
    workflow_dispatch:

jobs:
    build:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v3
              with:
                  submodules: true
                  fetch-depth: 0
                  ref: main

            - name: Setup Hugo
              uses: peaceiris/actions-hugo@v2
              with:
                  hugo-version: "0.108.0"
                  extended: true

            - name: Build Web
              run: hugo --minify

            - name: Import GPG key # import the gpg key to the github action
              uses: crazy-max/ghaction-import-gpg@v6 # repository https://github.com/crazy-max/ghaction-import-gpg
              with: # I use the subkey to sign the commit, if you use the primary key, you can refer to his repository docs.
                  gpg_private_key: ${
   {
    secrets.GPG_PRIVATE_KEY }} # the secret gpg subkey
                  passphrase: ${
   {
    secrets.PASSPHRASE }} # the passphrase of the gpg subkey
                  git_user_signingkey: true
                  git_commit_gpgsign: true
                  fingerprint: ${
   {
    secrets.FINGERPRINT }} # the fingerprint of the public subkey you use

            - name: Deploy Web
              uses: timerring/actions-gh-pages@v5.0.0 # this is adjusted action from peaceiris/actions-gh-pages, you can use it directly.
              with:
                  personal_token: ${
   {
    secrets.PERSONAL_TOKEN }} # the personal token of the github action
                  external_repository: your_username/your_repository # your target repository
                  publish_branch: main # the branch you want to deploy
                  publish_dir: ./public # the directory you want to deploy
                  user_name: ${
   {
    secrets.USER_NAME }} # the name of the github action
                  user_email: ${
   {
    secrets.USER_EMAIL }} # the email of the github action # ATTENTION: please add your github verified email
                  commit_message: ${
   {
    github.event.head_commit.message }}
目录
相关文章
|
10月前
|
Shell 网络安全 开发工具
Github Pages + Jekyll 独立博客一小时快速搭建&上线指南
Github Pages + Jekyll 独立博客一小时快速搭建&上线指南
|
5月前
|
JSON 缓存 JavaScript
使用 jsDelivr 免费加速 GitHub Pages 博客的静态资源(二)
使用 jsDelivr 加速 GitHub Pages 的图片资源和动态编译的 JSON 资源。
97 2
|
5月前
为什么 GitHub Pages 的文章标题不能以 @ 开头?
本文记录了一个 GitHub Pages 博客网页上文章标题以 `@` 开头导致的问题,并分析了原因,提供了解决方法。
71 0
|
7月前
GitHub——使用GitHub Pages生成在线文档
GitHub——使用GitHub Pages生成在线文档
50 0
|
10月前
|
资源调度 前端开发 JavaScript
不花一分钱,用Hexo和GitHub Pages搭建个人博客🏢
不花一分钱,用Hexo和GitHub Pages搭建个人博客🏢
200 0
|
JavaScript 开发工具 git
保姆级教程:从零构建GitHub Pages静态网站(下)
保姆级教程:从零构建GitHub Pages静态网站(下)
425 0
|
10月前
|
存储
github pages 部署单页面
github pages 部署单页面
160 0
|
10月前
|
缓存 网络协议 CDN
Docsify 配合 Github Pages 搭建一个自己的云笔记
Docsify 配合 Github Pages 搭建一个自己的云笔记
281 0
|
1月前
|
开发工具 git C++
【够用就好002】外行第一次发布github项目仓库
#deepseek#自学 记录外行学习代码的历程 今天是上传自己的工具代码到github仓库,一直以来是伸手党克隆别人的项目,今天在deepseek的辅导下上传自己的内容。
|
2月前
|
开发工具 git
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
221 69
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈

热门文章

最新文章