Skip to content

Commit 4ce19f2

Browse files
committed
Removed public key requirement, removed SigningConfig function, updated commit function and documentation
Signed-off-by: Dustin Lactin <[email protected]>
1 parent 43e1335 commit 4ce19f2

File tree

10 files changed

+110
-133
lines changed

10 files changed

+110
-133
lines changed

.github/actions/spelling/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ installationid
2121
jfrog
2222
mep
2323
myregistry
24+
openpgp
2425
PRIVATEKEYDATA
2526
repocreds
2627
rollbacked

cmd/main.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,28 @@ const applicationsAPIKindArgoCD = "argocd"
2828

2929
// ImageUpdaterConfig contains global configuration and required runtime data
3030
type ImageUpdaterConfig struct {
31-
ApplicationsAPIKind string
32-
ClientOpts argocd.ClientOptions
33-
ArgocdNamespace string
34-
DryRun bool
35-
CheckInterval time.Duration
36-
ArgoClient argocd.ArgoCD
37-
LogLevel string
38-
KubeClient *kube.KubernetesClient
39-
MaxConcurrency int
40-
HealthPort int
41-
MetricsPort int
42-
RegistriesConf string
43-
AppNamePatterns []string
44-
AppLabel string
45-
GitCommitUser string
46-
GitCommitMail string
47-
GitCommitMessage *template.Template
48-
GitCommitSigningKey string
49-
GitCommitSignOff bool
50-
DisableKubeEvents bool
51-
GitCreds git.CredsStore
31+
ApplicationsAPIKind string
32+
ClientOpts argocd.ClientOptions
33+
ArgocdNamespace string
34+
DryRun bool
35+
CheckInterval time.Duration
36+
ArgoClient argocd.ArgoCD
37+
LogLevel string
38+
KubeClient *kube.KubernetesClient
39+
MaxConcurrency int
40+
HealthPort int
41+
MetricsPort int
42+
RegistriesConf string
43+
AppNamePatterns []string
44+
AppLabel string
45+
GitCommitUser string
46+
GitCommitMail string
47+
GitCommitMessage *template.Template
48+
GitCommitSigningKey string
49+
GitCommitSigningMethod string
50+
GitCommitSignOff bool
51+
DisableKubeEvents bool
52+
GitCreds git.CredsStore
5253
}
5354

5455
// newRootCommand implements the root command of argocd-image-updater

cmd/run.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ func newRunCommand() *cobra.Command {
240240
runCmd.Flags().BoolVar(&warmUpCache, "warmup-cache", true, "whether to perform a cache warm-up on startup")
241241
runCmd.Flags().StringVar(&cfg.GitCommitUser, "git-commit-user", env.GetStringVal("GIT_COMMIT_USER", "argocd-image-updater"), "Username to use for Git commits")
242242
runCmd.Flags().StringVar(&cfg.GitCommitMail, "git-commit-email", env.GetStringVal("GIT_COMMIT_EMAIL", "[email protected]"), "E-Mail address to use for Git commits")
243-
runCmd.Flags().StringVar(&cfg.GitCommitSigningKey, "git-commit-signing-key", env.GetStringVal("GIT_COMMIT_SIGNING_KEY", ""), "GnuPG key ID or path to Public SSH Key used to sign the commits")
243+
runCmd.Flags().StringVar(&cfg.GitCommitSigningKey, "git-commit-signing-key", env.GetStringVal("GIT_COMMIT_SIGNING_KEY", ""), "GnuPG key ID or path to Private SSH Key used to sign the commits")
244+
runCmd.Flags().StringVar(&cfg.GitCommitSigningMethod, "git-commit-signing-method", env.GetStringVal("GIT_COMMIT_SIGNING_METHOD", "openpgp"), "Method used to sign Git commits ('openpgp' or 'ssh')")
244245
runCmd.Flags().BoolVar(&cfg.GitCommitSignOff, "git-commit-sign-off", env.GetBoolVal("GIT_COMMIT_SIGN_OFF", false), "Whether to sign-off git commits")
245246
runCmd.Flags().StringVar(&commitMessagePath, "git-commit-message-path", defaultCommitTemplatePath, "Path to a template to use for Git commit messages")
246247
runCmd.Flags().BoolVar(&cfg.DisableKubeEvents, "disable-kube-events", env.GetBoolVal("IMAGE_UPDATER_KUBE_EVENTS", false), "Disable kubernetes events")
@@ -321,18 +322,19 @@ func runImageUpdater(cfg *ImageUpdaterConfig, warmUp bool) (argocd.ImageUpdaterR
321322
defer sem.Release(1)
322323
log.Debugf("Processing application %s", app)
323324
upconf := &argocd.UpdateConfiguration{
324-
NewRegFN: registry.NewClient,
325-
ArgoClient: cfg.ArgoClient,
326-
KubeClient: cfg.KubeClient,
327-
UpdateApp: &curApplication,
328-
DryRun: dryRun,
329-
GitCommitUser: cfg.GitCommitUser,
330-
GitCommitEmail: cfg.GitCommitMail,
331-
GitCommitMessage: cfg.GitCommitMessage,
332-
GitCommitSigningKey: cfg.GitCommitSigningKey,
333-
GitCommitSignOff: cfg.GitCommitSignOff,
334-
DisableKubeEvents: cfg.DisableKubeEvents,
335-
GitCreds: cfg.GitCreds,
325+
NewRegFN: registry.NewClient,
326+
ArgoClient: cfg.ArgoClient,
327+
KubeClient: cfg.KubeClient,
328+
UpdateApp: &curApplication,
329+
DryRun: dryRun,
330+
GitCommitUser: cfg.GitCommitUser,
331+
GitCommitEmail: cfg.GitCommitMail,
332+
GitCommitMessage: cfg.GitCommitMessage,
333+
GitCommitSigningKey: cfg.GitCommitSigningKey,
334+
GitCommitSigningMethod: cfg.GitCommitSigningMethod,
335+
GitCommitSignOff: cfg.GitCommitSignOff,
336+
DisableKubeEvents: cfg.DisableKubeEvents,
337+
GitCreds: cfg.GitCreds,
336338
}
337339
res := argocd.UpdateApplication(upconf, syncState)
338340
result.NumApplicationsProcessed += 1

docs/basics/update-methods.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ format. To create such a secret from an existing private key, you can use
153153

154154
```bash
155155
kubectl -n argocd-image-updater create secret generic git-creds \
156-
--from-file=sshPrivateKey=~/.ssh/id_rsa \
157-
--from-file=sshPublicKey=~/.ssh/id_rsa.pub \
156+
--from-file=sshPrivateKey=~/.ssh/id_rsa
158157
```
159158

160159
### <a name="method-git-repository"></a>Specifying a repository when using a Helm repository in repoURL
@@ -248,44 +247,48 @@ as the author. You can override the author using the
248247
`git.user` and `git.email`
249248
in the `argocd-image-updater-config` ConfigMap.
250249

251-
### <a name="method-git-commit-signing"></a>Enabling commit signature verification using an SSH or GPG key
252-
Commit signing requires the repository be accessed using HTTPS or SSH with a user account.
250+
## <a name="method-git-commit-signing"></a>Enabling commit signature signing using an SSH or GPG key
251+
252+
### 1. SCM branch protection rules require signed commits
253+
Commit signing for SCM branch protection rules require the repository be accessed using HTTPS or SSH with a user account.
253254
Repositories accessed using a GitHub App can not be verified when using the git command line at this time.
254255

255-
Each Git commit associated with an author's name and email address can be signed via a public SSH key or GPG key.
256+
Each Git commit associated with an author's name and email address can be signed via a private SSH key or GPG key.
257+
256258
Commit signing requires a bot account with a GPG or SSH key and the username and email address configured to match the bot account.
257259

258-
Your preferred signing key must be associated with your bot account. See provider documentation for further details:
260+
Your preferred signing key must be associated with your bot account. See SCM provider documentation for further details:
259261
* [GitHub](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
260262
* [GitLab](https://docs.gitlab.com/ee/user/project/repository/signed_commits/)
261263
* [Bitbucket](https://confluence.atlassian.com/bitbucketserver/controlling-access-to-code-776639770.html)
262264

263-
Commit Sign Off can be enabled by setting `git.commit-sign-off: "true"`
265+
### 2. Signing commits for future use with ArgoCD Source Verification Policies
266+
Commits can also be signed for use with source verification.
267+
In this case signing keys do not need to be associated with an SCM user account.
264268

265269
**SSH:**
266270

267-
Both private and public keys must be mounted and accessible on the `argocd-image-updater` pod.
271+
The private key must be mounted and accessible on the `argocd-image-updater` pod.
268272

269-
Set `git.commit-signing-key` `argocd-image-updater-config` ConfigMap to the path of your public key:
273+
Set `git.commit-signing-key` `argocd-image-updater-config` ConfigMap to the path of your private key:
270274

271275
```yaml
272276
data:
273277
git.commit-sign-off: "true"
274-
git.commit-signing-key: /app/.ssh/id_rsa.pub
278+
git.commit-signing-key: /app/.ssh/id_rsa
279+
git.commit-signing-method: "ssh"
275280
```
276281

277-
The matching private key must be available in the same location.
278-
279-
Create a new SSH secret or add the public key to your existing SSH secret:
282+
Create a new SSH secret or use your existing SSH secret:
280283
```bash
281284
kubectl -n argocd-image-updater create secret generic ssh-git-creds \
282-
--from-file=sshPrivateKey=~/.ssh/id_rsa \
283-
--from-file=sshPublicKey=~/.ssh/id_rsa.pub
285+
--from-file=sshPrivateKey=~/.ssh/id_rsa
284286
```
285287

286288
**GPG:**
287289

288290
The GPG private key must be installed and available in the `argocd-image-updater` pod.
291+
The `git.commit-signing-method` defaults to `openpgp`.
289292
Set `git.commit-signing-key` in the `argocd-image-updater-config` ConfigMap to the GPG key ID you want to use:
290293

291294
```yaml
@@ -294,6 +297,8 @@ data:
294297
git.commit-signing-key: 3AA5C34371567BD2
295298
```
296299

300+
#### Commit Sign Off can be enabled by setting `git.commit-sign-off: "true"`
301+
297302
### <a name="method-git-commit-message"></a>Changing the Git commit message
298303

299304
You can change the default commit message used by Argo CD Image Updater to some

ext/git/client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ type Client interface {
8282
Add(path string) error
8383
SymRefToBranch(symRef string) (string, error)
8484
Config(username string, email string) error
85-
SigningConfig(signingkey string) error
8685
}
8786

8887
type EventHandlers struct {

ext/git/writer.go

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package git
33
import (
44
"fmt"
55
"os/exec"
6-
"regexp"
76
"strings"
87

98
"github.com/argoproj-labs/argocd-image-updater/pkg/log"
@@ -15,8 +14,10 @@ type CommitOptions struct {
1514
CommitMessageText string
1615
// CommitMessagePath holds the path to a file to be used for the commit message (-F option)
1716
CommitMessagePath string
18-
// SigningKey holds a GnuPG key ID or path to Public SSH Key used to sign the commit with (-S option)
17+
// SigningKey holds a GnuPG key ID or path to a Private SSH Key used to sign the commit with (-S option)
1918
SigningKey string
19+
// SigningMethod holds the signing method used to sign commits. (git -c gpg.format=ssh option)
20+
SigningMethod string
2021
// SignOff specifies whether to sign-off a commit (-s option)
2122
SignOff bool
2223
}
@@ -26,25 +27,18 @@ type CommitOptions struct {
2627
// changes will be commited. If message is not the empty string, it will be
2728
// used as the commit message, otherwise a default commit message will be used.
2829
// If signingKey is not the empty string, commit will be signed with the given
29-
// GPG key.
30+
// GPG or SSH key.
3031
func (m *nativeGitClient) Commit(pathSpec string, opts *CommitOptions) error {
3132
defaultCommitMsg := "Update parameters"
32-
args := []string{"commit"}
33+
// Git configuration
34+
config := "gpg.format=" + opts.SigningMethod
35+
args := []string{"-c", config, "commit"}
3336
if pathSpec == "" || pathSpec == "*" {
3437
args = append(args, "-a")
3538
}
36-
if opts.SigningKey != "" {
37-
// Check if SiginingKey is a GPG key or Public SSH Key
38-
keyCheck, err := regexp.MatchString(".*pub$", opts.SigningKey)
39-
if err != nil {
40-
return fmt.Errorf("could not validate Signing Key as GPG or Public SSH Key: %v", err)
41-
}
42-
if keyCheck {
43-
args = append(args, "-S")
44-
} else {
45-
args = append(args, "-S", opts.SigningKey)
46-
}
47-
}
39+
// Commit fails with a space between -S flag and path to SSH key
40+
// -S/user/test/.ssh/signingKey or -SAAAAAAAA...
41+
args = append(args, fmt.Sprintf("-S%s", opts.SigningKey))
4842
if opts.SignOff {
4943
args = append(args, "-s")
5044
}
@@ -157,28 +151,3 @@ func (m *nativeGitClient) runCredentialedCmdWithOutput(args ...string) (string,
157151
cmd.Env = append(cmd.Env, environ...)
158152
return m.runCmdOutput(cmd, runOpts{})
159153
}
160-
161-
// SigningConfig configures commit signing for the repository
162-
func (m *nativeGitClient) SigningConfig(signingkey string) error {
163-
// Check if SiginingKey is a GPG key or Public SSH Key
164-
keyCheck, err := regexp.MatchString(".*pub$", signingkey)
165-
if err != nil {
166-
return fmt.Errorf("could not validate Signing Key as GPG or Public SSH Key: %v", err)
167-
}
168-
if keyCheck {
169-
// Setting the GPG format to ssh
170-
log.Warnf("Setting GPG Format to SSH")
171-
_, err = m.runCmd("config", "gpg.format", "ssh")
172-
if err != nil {
173-
return fmt.Errorf("could not set gpg format to ssh: %v", err)
174-
}
175-
// Setting Public SSH Key as our signing key
176-
// SSH Keys can not currently be set via cli flag
177-
_, err = m.runCmd("config", "user.signingkey", signingkey)
178-
if err != nil {
179-
return fmt.Errorf("could not set git signing key: %v", err)
180-
}
181-
}
182-
183-
return nil
184-
}

manifests/base/deployment/argocd-image-updater-deployment.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ spec:
8383
key: git.commit-signing-key
8484
name: argocd-image-updater-config
8585
optional: true
86+
- name: GIT_COMMIT_SIGNING_METHOD
87+
valueFrom:
88+
configMapKeyRef:
89+
key: git.commit-signing-key
90+
name: argocd-image-updater-config
91+
optional: true
8692
- name: GIT_COMMIT_SIGN_OFF
8793
valueFrom:
8894
configMapKeyRef:
@@ -132,10 +138,6 @@ spec:
132138
mountPath: /app/.ssh/id_rsa
133139
readOnly: true
134140
subPath: sshPrivateKey
135-
- name: ssh-signing-key
136-
mountPath: /app/.ssh/id_rsa.pub
137-
readOnly: true
138-
subPath: sshPublicKey
139141
serviceAccountName: argocd-image-updater
140142
volumes:
141143
- configMap:

manifests/install.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ spec:
164164
key: git.commit-signing-key
165165
name: argocd-image-updater-config
166166
optional: true
167+
- name: GIT_COMMIT_SIGNING_METHOD
168+
valueFrom:
169+
configMapKeyRef:
170+
key: git.commit-signing-key
171+
name: argocd-image-updater-config
172+
optional: true
167173
- name: GIT_COMMIT_SIGN_OFF
168174
valueFrom:
169175
configMapKeyRef:
@@ -215,10 +221,6 @@ spec:
215221
name: ssh-signing-key
216222
readOnly: true
217223
subPath: sshPrivateKey
218-
- mountPath: /app/.ssh/id_rsa.pub
219-
name: ssh-signing-key
220-
readOnly: true
221-
subPath: sshPublicKey
222224
serviceAccountName: argocd-image-updater
223225
volumes:
224226
- configMap:

pkg/argocd/git.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,6 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
169169
}
170170
}
171171

172-
// Set commit signing configuration
173-
if wbc.GitCommitSigningKey != "" {
174-
err = gitC.SigningConfig(wbc.GitCommitSigningKey)
175-
if err != nil {
176-
return err
177-
}
178-
}
179-
180172
// The branch to checkout is either a configured branch in the write-back
181173
// config, or taken from the application spec's targetRevision. If the
182174
// target revision is set to the special value HEAD, or is the empty
@@ -246,6 +238,7 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
246238
commitOpts.SigningKey = wbc.GitCommitSigningKey
247239
}
248240

241+
commitOpts.SigningMethod = wbc.GitCommitSigningMethod
249242
commitOpts.SignOff = wbc.GitCommitSignOff
250243

251244
err = gitC.Commit("", commitOpts)

0 commit comments

Comments
 (0)