Skip to content

Commit 4dc9eae

Browse files
phorcys420matifali
andauthored
feat: add git-commit-signing module (coder#94)
* feat: add git-commit-signing module * feat(git-commit-signing): check for git and jq * fix(git-commit-signing): only use icon once * fix(git-commit-signing): fix typo in README Co-authored-by: Muhammad Atif Ali <matifali@live.com> * bun fmt * chore: clarify readme SSH key paragraph * fix: add `curl` as dependency * feat: download keys to ~/.ssh/git-commit-signing * feat: add conflict disclaimer --------- Co-authored-by: Muhammad Atif Ali <matifali@live.com> Co-authored-by: Atif Ali <atif@coder.com>
1 parent e2f4fcb commit 4dc9eae

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

git-commit-signing/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
display_name: Git commit signing
3+
description: Configures Git to sign commits using your Coder SSH key
4+
icon: ../.icons/git.svg
5+
maintainer_github: phorcys420
6+
verified: false
7+
tags: [helper, git]
8+
---
9+
10+
# git-commit-signing
11+
12+
This module downloads your SSH key from Coder and uses it to sign commits with Git.
13+
It requires `curl` and `jq` to be installed inside your workspace.
14+
15+
Please observe that using the SSH key that's part of your Coder account for commit signing, means that in the event of a breach of your Coder account, or a malicious admin, someone could perform commit signing pretending to be you.
16+
17+
This module has a chance of conflicting with the user's dotfiles / the personalize module if one of those has configuration directives that overwrite this module's / each other's git configuration.
18+
19+
```hcl
20+
module "git-commit-signing" {
21+
source = "https://registry.coder.com/modules/git-commit-signing"
22+
agent_id = coder_agent.example.id
23+
}
24+
```

git-commit-signing/main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
coder = {
6+
source = "coder/coder"
7+
version = ">= 0.12"
8+
}
9+
}
10+
}
11+
12+
variable "agent_id" {
13+
type = string
14+
description = "The ID of a Coder agent."
15+
}
16+
17+
resource "coder_script" "git-commit-signing" {
18+
display_name = "Git commit signing"
19+
icon = "https://raw.githubusercontent.com/coder/modules/main/.icons/git.svg"
20+
21+
script = file("${path.module}/run.sh")
22+
run_on_start = true
23+
24+
agent_id = var.agent_id
25+
}

git-commit-signing/run.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env sh
2+
3+
if ! command -v git > /dev/null; then
4+
echo "git is not installed"
5+
exit 1
6+
fi
7+
8+
if ! command -v curl > /dev/null; then
9+
echo "curl is not installed"
10+
exit 1
11+
fi
12+
13+
if ! command -v jq > /dev/null; then
14+
echo "jq is not installed"
15+
exit 1
16+
fi
17+
18+
mkdir -p ~/.ssh/git-commit-signing
19+
20+
echo "Downloading SSH key"
21+
22+
ssh_key=$(curl --request GET \
23+
--url "${CODER_AGENT_URL}api/v2/workspaceagents/me/gitsshkey" \
24+
--header "Coder-Session-Token: ${CODER_AGENT_TOKEN}")
25+
26+
jq --raw-output ".public_key" > ~/.ssh/git-commit-signing/coder.pub <<EOF
27+
$ssh_key
28+
EOF
29+
30+
jq --raw-output ".private_key" > ~/.ssh/git-commit-signing/coder <<EOF
31+
$ssh_key
32+
EOF
33+
34+
chmod -R 400 ~/.ssh/git-commit-signing/coder
35+
chmod -R 400 ~/.ssh/git-commit-signing/coder.pub
36+
37+
echo "Configuring git to use the SSH key"
38+
39+
git config --global gpg.format ssh
40+
git config --global commit.gpgsign true
41+
git config --global user.signingkey ~/.ssh/git-commit-signing/coder

0 commit comments

Comments
 (0)