Skip to content

Commit be718e2

Browse files
authored
feat: GPG commit signature verification (#2492) (#3242)
* Add initial primitives and tests for GPG related operations * More tests and test documentation * Move gpg primitives to own module * Add initial primitives for running git verify-commit and tests * Improve and better comment test * Implement VerifyCommitSignature() primitive for metrics wrapper * More commentary * Make reposerver verify gpg signatures when generating manifests * Make signature validation optional * Forbid use of local manifests when signature verification is enabled * Introduce new signatureKeys field in project CRD * Initial support for only syncing against signed revisions * Updates to GnuPG primitives and more test cases * Move signature verification to correct place and add tests * Add signature verification result to revision metadata and display it in UI * Add more primitives and move out some stuff to common module * Add more testdata * Add key management primitives to ArgoDB * Move type GnuPGPublicKey to appsv1 package * Add const ArgoCDGPGKeysConfigMapName * Handle key operations with appsv1.GnuPGPublicKey * Add initial API for managing GPG keys * Remove deprecated code * Add primitives for adding public keys to configuration * Change semantics of ValidateGPGKeys to return more key information * Add key import functionality to public key API * Fix code quirks reported by linter * More code quirks fixes * Fix test * Add primitives for deleting keys from configuration * Add delete key operation to API and CLI * Cosmetics * Implement logic to sync configuration to keyring in repo-server * Add IsGPGEnabled() primitive and also update trustdb on ownertrust changes * Use gpg.IsGPGEnabled() instead of custom test * Remove all keyring manipulating methods from DB * Cosmetics/comments * Require grpc methods from argoproj pkg * Enable setting config path via ARGOCD_GPG_DATA_PATH * Allow "no" and any cases in ARGOCD_GPG_ENABLED * Enable GPG feature on start and start-e2e and set required environment * Cosmetics/comments * Cosmetics and commentary * Update API documentation * Fix comment * Only run GPG related operations if GPG is enabled * Allow setting ARGOCD_GPG_ENABLE from the environment * Create GPG ConfigMap resource during installation * Use function instead of constant to get the watcher path * Re-watch source path in case it gets recreated. Also, error on finish * Add End-to-End tests for GPG commit verification * Introduce SignatureKey type for AppProject CRD * Fix merge error from previous commit * Adapt test for additional manifest (argocd-gpg-keys-cm.yaml) * Fix linter issues * Adapt CircleCI configuration to enable running tests * Add wrapper scripts for git and gpg * Sigh. * Display gpg version in CircleCI * Install gnupg2 and link it to gpg in CI * Try to install gnupg2 in CircleCI image * More CircleCI tweaks * # This is a combination of 10 commits. # This is the 1st commit message: Containerize tests - test cycle # This is the commit message #2: adapt working directory # This is the commit message #3: Build before running tests (so we might have a cache) # This is the commit message #4: Test limiting parallelism # This is the commit message #5: Remove unbound variable # This is the commit message #6: Decrease parallelism to find out limit # This is the commit message #7: Use correct flag # This is the commit message #8: Update Docker image # This is the commit message #9: Remove build phase and increase parallelism # This is the commit message #10: Further increase parallelism * Dockerize toolchain * Add new targets to Makefile * Codegen * Properly handle permissions for E2E tests * Remove gnupg2 installation from CircleCI configuration * Limit parallelism of build * Fix Yarn lint * Retrigger CI for possible flaky test * Codegen * Remove duplicate target in Makefile * Pull in pager from dep ensure -v * Adapt to gitops-engine changes and codegen * Use new health package for health status constants * Add GPG methods to ArgoDB mock module * Fix possible nil pointer dereference * Fix linter issue in imports * Introduce RBAC resource type 'gpgkeys' and adapt policies * Use ARGOCD_GNUPGHOME instead of GNUPGHOME for subsystem configuration Also remove some deprecated unit tests. * Also register GPG keys API with gRPC-GW * Update from codegen * Update GPG key API * Add web UI to manage GPG keys * Lint updates * Change wording * Add some plausibility checks for supplied data on key creation * Update from codegen * Re-allow binary keys and move check for ASCII armoured to UI * Make yarn lint happy * Add editing signature keys for projects in UI * Add ability to configure signature keys for project in CLI * Change default value to use for GNUPGHOME * Do not include data section in default gpg keys CM * Adapt Docker image for GnuPG feature * Add required configuration to installation manifests * Add add-signature-key and remove-signature-key commands to project CLI * Fix typo * Add initial user documentation for GnuPG verification * Fix role name - oops * Mention required RBAC roles in docs * Support GPG verification of git annotated tags as well * Ensure CLI can build succesfully * Better support verification on tags * Print key type in upper case * Update user documentation * Correctly disable GnuPG verification if ARGOCD_GPG_ENABLE=false * Clarify that this feature is only available with Git repositories * codegen * Move verification code to own function * Remove deprecated check * Make things more developer friendly when running locally * Enable GPG feature by default, and don't require ARGOCD_GNUPGHOME to be set * Revert changes to manifests to reflect default enable state * Codegen
1 parent a886241 commit be718e2

File tree

95 files changed

+7781
-633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+7781
-633
lines changed

Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ RUN groupadd -g 999 argocd && \
5050
chmod g=u /home/argocd && \
5151
chmod g=u /etc/passwd && \
5252
apt-get update && \
53-
apt-get install -y git git-lfs python3-pip tini && \
53+
apt-get install -y git git-lfs python3-pip tini gpg && \
5454
apt-get clean && \
5555
pip3 install awscli==1.18.80 && \
5656
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
5757

5858
COPY hack/git-ask-pass.sh /usr/local/bin/git-ask-pass.sh
59+
COPY hack/gpg-wrapper.sh /usr/local/bin/gpg-wrapper.sh
60+
COPY hack/git-verify-wrapper.sh /usr/local/bin/git-verify-wrapper.sh
5961
COPY --from=builder /usr/local/bin/ks /usr/local/bin/ks
6062
COPY --from=builder /usr/local/bin/helm2 /usr/local/bin/helm2
6163
COPY --from=builder /usr/local/bin/helm /usr/local/bin/helm
@@ -71,6 +73,10 @@ RUN mkdir -p /app/config/ssh && \
7173
ln -s /app/config/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts
7274

7375
RUN mkdir -p /app/config/tls
76+
RUN mkdir -p /app/config/gpg/source && \
77+
mkdir -p /app/config/gpg/keys && \
78+
chown argocd /app/config/gpg/keys && \
79+
chmod 0700 /app/config/gpg/keys
7480

7581
# workaround ksonnet issue https://github.com/ksonnet/ksonnet/issues/298
7682
ENV USER=argocd

Makefile

+18-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ IMAGE_NAMESPACE?=
9898
STATIC_BUILD?=true
9999
# build development images
100100
DEV_IMAGE?=false
101+
ARGOCD_GPG_ENABLED?=true
102+
ARGOCD_E2E_APISERVER_PORT?=8080
101103

102104
override LDFLAGS += \
103105
-X ${PACKAGE}.version=${VERSION} \
@@ -159,6 +161,8 @@ codegen:
159161

160162
.PHONY: cli
161163
cli: clean-debug
164+
rm -f ${DIST_DIR}/${CLI_NAME}
165+
mkdir -p ${DIST_DIR}
162166
CGO_ENABLED=0 ${PACKR_CMD} build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${CLI_NAME} ./cmd/argocd
163167

164168
.PHONY: cli-docker
@@ -331,7 +335,7 @@ test-e2e:
331335
test-e2e-local: cli
332336
# NO_PROXY ensures all tests don't go out through a proxy if one is configured on the test system
333337
export GO111MODULE=off
334-
NO_PROXY=* ./hack/test.sh -timeout 15m -v ./test/e2e
338+
ARGOCD_GPG_ENABLED=true NO_PROXY=* ./hack/test.sh -timeout 15m -v ./test/e2e
335339

336340
# Spawns a shell in the test server container for debugging purposes
337341
debug-test-server:
@@ -354,9 +358,17 @@ start-e2e-local:
354358
kubectl create ns argocd-e2e || true
355359
kubectl config set-context --current --namespace=argocd-e2e
356360
kustomize build test/manifests/base | kubectl apply -f -
361+
# Create GPG keys and source directories
362+
if test -d /tmp/argo-e2e/app/config/gpg; then rm -rf /tmp/argo-e2e/app/config/gpg/*; fi
363+
mkdir -p /tmp/argo-e2e/app/config/gpg/keys && chmod 0700 /tmp/argo-e2e/app/config/gpg/keys
364+
mkdir -p /tmp/argo-e2e/app/config/gpg/source && chmod 0700 /tmp/argo-e2e/app/config/gpg/source
365+
if test "$(USER_ID)" != ""; then chown -R "$(USER_ID)" /tmp/argo-e2e; fi
357366
# set paths for locally managed ssh known hosts and tls certs data
358367
ARGOCD_SSH_DATA_PATH=/tmp/argo-e2e/app/config/ssh \
359368
ARGOCD_TLS_DATA_PATH=/tmp/argo-e2e/app/config/tls \
369+
ARGOCD_GPG_DATA_PATH=/tmp/argo-e2e/app/config/gpg/source \
370+
ARGOCD_GNUPGHOME=/tmp/argo-e2e/app/config/gpg/keys \
371+
ARGOCD_GPG_ENABLED=true \
360372
ARGOCD_E2E_DISABLE_AUTH=false \
361373
ARGOCD_ZJWT_FEATURE_FLAG=always \
362374
ARGOCD_IN_CI=$(ARGOCD_IN_CI) \
@@ -383,8 +395,13 @@ start-local: mod-vendor-local
383395
# check we can connect to Docker to start Redis
384396
killall goreman || true
385397
kubectl create ns argocd || true
398+
rm -rf /tmp/argocd-local
399+
mkdir -p /tmp/argocd-local
400+
mkdir -p /tmp/argocd-local/gpg/keys && chmod 0700 /tmp/argocd-local/gpg/keys
401+
mkdir -p /tmp/argocd-local/gpg/source
386402
ARGOCD_ZJWT_FEATURE_FLAG=always \
387403
ARGOCD_IN_CI=false \
404+
ARGOCD_GPG_ENABLED=true \
388405
ARGOCD_E2E_TEST=false \
389406
goreman -f $(ARGOCD_PROCFILE) start ${ARGOCD_START}
390407

Procfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
controller: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:=/tmp/argocd/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:=/tmp/argocd/ssh} go run ./cmd/argocd-application-controller/main.go --loglevel debug --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081}"
2-
api-server: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:=/tmp/argocd/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:=/tmp/argocd/ssh} go run ./cmd/argocd-server/main.go --loglevel debug --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --disable-auth=${ARGOCD_E2E_DISABLE_AUTH:-'true'} --insecure --dex-server http://localhost:${ARGOCD_E2E_DEX_PORT:-5556} --repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081} --port ${ARGOCD_E2E_APISERVER_PORT:-8080} --staticassets ui/dist/app"
1+
controller: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} go run ./cmd/argocd-application-controller/main.go --loglevel debug --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081}"
2+
api-server: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} go run ./cmd/argocd-server/main.go --loglevel debug --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --disable-auth=${ARGOCD_E2E_DISABLE_AUTH:-'true'} --insecure --dex-server http://localhost:${ARGOCD_E2E_DEX_PORT:-5556} --repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081} --port ${ARGOCD_E2E_APISERVER_PORT:-8080} --staticassets ui/dist/app"
33
dex: sh -c "go run github.com/argoproj/argo-cd/cmd/argocd-util gendexcfg -o `pwd`/dist/dex.yaml && docker run --rm -p ${ARGOCD_E2E_DEX_PORT:-5556}:${ARGOCD_E2E_DEX_PORT:-5556} -v `pwd`/dist/dex.yaml:/dex.yaml quay.io/dexidp/dex:v2.22.0 serve /dex.yaml"
44
redis: docker run --rm --name argocd-redis -i -p ${ARGOCD_E2E_REDIS_PORT:-6379}:${ARGOCD_E2E_REDIS_PORT:-6379} redis:5.0.8-alpine --save "" --appendonly no --port ${ARGOCD_E2E_REDIS_PORT:-6379}
5-
repo-server: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:=/tmp/argocd/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:=/tmp/argocd/ssh} go run ./cmd/argocd-repo-server/main.go --loglevel debug --port ${ARGOCD_E2E_REPOSERVER_PORT:-8081} --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379}"
5+
repo-server: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_GNUPGHOME=${ARGOCD_GNUPGHOME:-/tmp/argocd-local/gpg/keys} ARGOCD_GPG_DATA_PATH=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source} ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} go run ./cmd/argocd-repo-server/main.go --loglevel debug --port ${ARGOCD_E2E_REPOSERVER_PORT:-8081} --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379}"
66
ui: sh -c 'cd ui && ${ARGOCD_E2E_YARN_CMD:-yarn} start'
77
git-server: test/fixture/testrepos/start-git.sh
8-
dev-mounter: [[ "$ARGOCD_E2E_TEST" != "true" ]] && go run hack/dev-mounter/main.go --configmap argocd-ssh-known-hosts-cm=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd/ssh} --configmap argocd-tls-certs-cm=${ARGOCD_TLS_DATA_PATH:=/tmp/argocd/tls}
8+
dev-mounter: [[ "$ARGOCD_E2E_TEST" != "true" ]] && go run hack/dev-mounter/main.go --configmap argocd-ssh-known-hosts-cm=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} --configmap argocd-tls-certs-cm=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} --configmap argocd-gpg-keys-cm=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source}

assets/builtin-policy.csv

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ p, role:readonly, clusters, get, *, allow
1212
p, role:readonly, repositories, get, *, allow
1313
p, role:readonly, projects, get, *, allow
1414
p, role:readonly, accounts, get, *, allow
15+
p, role:readonly, gpgkeys, get, *, allow
1516

1617
p, role:admin, applications, create, */*, allow
1718
p, role:admin, applications, update, */*, allow
@@ -32,6 +33,8 @@ p, role:admin, projects, create, *, allow
3233
p, role:admin, projects, update, *, allow
3334
p, role:admin, projects, delete, *, allow
3435
p, role:admin, accounts, update, *, allow
36+
p, role:admin, gpgkeys, create, *, allow
37+
p, role:admin, gpgkeys, delete, *, allow
3538

3639
g, role:admin, role:readonly
3740
g, admin, role:admin

0 commit comments

Comments
 (0)