Appendix A: Cheat Sheet
This appendix is meant for looking things up, not for reading
straight through. For each tool you will find the commands and YAML
snippets you need most often in the labs. Each snippet has one line of
explanation. The values match the lab conventions from Chapter 0:
registries localhost:5001 (build) and
localhost:5002 (target), Vault at
localhost:8200, Nexus at localhost:8081.
Warning: Passwords and tokens in this appendix are lab values. In real environments they belong in a secret store, never in the shell history or a repository.
Tip: Flags change between versions. If a command does not work, first check
<werkzeug> --versionand<werkzeug> <befehl> --help.
GitLab CI (see Chapter 1)
Basic structure of a pipeline with stages and dependencies:
stages: [build, scan, sign, deploy]
build:
stage: build
image: docker:27
services: [docker:27-dind]
script:
- docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"Run a job only on the main branch or for tags:
deploy:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_TAG
script: ["./deploy.sh"]Pass a job’s results on as an artifact and depend on it explicitly:
sbom:
stage: scan
script: ["syft dir:. -o cyclonedx-json=sbom.cdx.json"]
artifacts:
paths: [sbom.cdx.json]
expire_in: 30 days
grype:
stage: scan
needs: ["sbom"]
script: ["grype sbom:./sbom.cdx.json --fail-on high"]Include shared templates from a central repo:
include:
- project: platform/ci-templates
ref: v1.4.0
file: /templates/security-scans.ymlRegister a runner non-interactively (new token workflow since GitLab 16):
gitlab-runner register --non-interactive \
--url http://localhost:8929 \
--token glrt-LAB-TOKEN \
--executor docker \
--docker-image alpine:3.20Validate the pipeline file before committing: in the GitLab UI under Build > Pipeline editor > Validate (CI Lint).
Jenkins (see Chapter 1)
Declarative pipeline (Jenkinsfile) with credentials from
the Jenkins store:
pipeline {
agent any
options { timeout(time: 30, unit: 'MINUTES') }
stages {
stage('Build') {
steps { sh 'docker build -t localhost:5001/demo-app:1.0.0 .' }
}
stage('Push') {
steps {
withCredentials([usernamePassword(credentialsId: 'reg-build',
usernameVariable: 'REG_USER', passwordVariable: 'REG_PASS')]) {
sh '''
echo "$REG_PASS" | docker login localhost:5001 \\
-u "$REG_USER" --password-stdin
docker push localhost:5001/demo-app:1.0.0
'''
}
}
}
}
post { always { archiveArtifacts artifacts: '*.json', allowEmptyArchive: true } }
}Read the initial admin password from the container:
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPasswordStart a job via the Jenkins CLI and wait for it to finish:
curl -sO http://localhost:8090/jnlpJars/jenkins-cli.jar
java -jar jenkins-cli.jar -s http://localhost:8090/ \
-auth admin:API-TOKEN build demo-pipeline -s -vList installed plugins (for inventory and update planning):
java -jar jenkins-cli.jar -s http://localhost:8090/ \
-auth admin:API-TOKEN list-pluginsSecurity: Never print secrets with
echoin Jenkins.withCredentialsmasks them in the log, but only if they are printed unchanged.
Argo CD (see Chapter 1)
Get the initial admin password and log in:
argocd admin initial-password -n argocd
argocd login localhost:8443 --insecure --username admin \
--password 'LAB-PASSWORT'Create an application via the CLI:
argocd app create demo \
--repo http://gitlab.local/demo/demo-app.git --path k8s \
--dest-server https://kubernetes.default.svc --dest-namespace demoStatus, differences and synchronization:
argocd app get demo # sync and health status
argocd app diff demo # drift Git vs. cluster
argocd app sync demo # sync manually
argocd app history demo # previous deployments
argocd app rollback demo 3 # roll back to history ID 3Declarative Application with automatic sync:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: demo
namespace: argocd
spec:
project: default
source:
repoURL: http://gitlab.local/demo/demo-app.git
targetRevision: main
path: k8s
destination:
server: https://kubernetes.default.svc
namespace: demo
syncPolicy:
automated: { prune: true, selfHeal: true }
syncOptions: ["CreateNamespace=true"]Flux (see Chapter 1)
Flux is not part of the standard lab. Install the flux
CLI separately if you need it.
flux check --pre # check cluster prerequisites
flux install # install controllers without Git bootstrapCreate a Git source and a Kustomization:
flux create source git demo \
--url=http://gitlab.local/demo/demo-app.git \
--branch=main --interval=1m
flux create kustomization demo \
--source=GitRepository/demo --path="./k8s" \
--prune=true --interval=5m --target-namespace=demoCheck status, reconcile immediately, pause:
flux get sources git
flux get kustomizations
flux reconcile kustomization demo --with-source
flux suspend kustomization demo
flux resume kustomization demo
flux logs --level=errorNexus Repository REST API (see Chapter 3)
Check availability and write readiness:
curl -s -o /dev/null -w '%{http_code}\n' \
http://localhost:8081/service/rest/v1/status # 200 = running
curl -s -o /dev/null -w '%{http_code}\n' \
http://localhost:8081/service/rest/v1/status/writable # 200 = writableInitial admin password from the container:
docker exec nexus cat /nexus-data/admin.passwordList repositories:
curl -s -u admin:LAB-PASSWORT \
http://localhost:8081/service/rest/v1/repositories | jq '.[].name'Create a Docker proxy repository for Docker Hub via the API:
curl -s -u admin:LAB-PASSWORT -H 'Content-Type: application/json' \
-X POST http://localhost:8081/service/rest/v1/repositories/docker/proxy \
-d @docker-proxy.json{
"name": "dockerhub-proxy",
"online": true,
"storage": { "blobStoreName": "default", "strictContentTypeValidation": true },
"proxy": { "remoteUrl": "https://registry-1.docker.io",
"contentMaxAge": 1440, "metadataMaxAge": 1440 },
"negativeCache": { "enabled": true, "timeToLive": 1440 },
"httpClient": { "blocked": false, "autoBlock": true },
"docker": { "v1Enabled": false, "forceBasicAuth": true, "httpPort": 8082 },
"dockerProxy": { "indexType": "HUB" }
}Search for components in a repository:
curl -s -u admin:LAB-PASSWORT \
'http://localhost:8081/service/rest/v1/search?repository=pypi-proxy&name=flask' \
| jq '.items[] | {name, version}'Harbor REST API (see Chapter 3)
Harbor is optional in the lab. The API lives under
/api/v2.0. Replace harbor.local with your
host.
# List projects
curl -s -u admin:LAB-PASSWORT https://harbor.local/api/v2.0/projects \
| jq '.[].name'
# Create a private project
curl -s -u admin:LAB-PASSWORT -H 'Content-Type: application/json' \
-X POST https://harbor.local/api/v2.0/projects \
-d '{"project_name":"demo","metadata":{"public":"false"}}'Query artifacts including the scan overview:
H=https://harbor.local/api/v2.0/projects/demo/repositories/demo-app
curl -s -u admin:LAB-PASSWORT \
"$H/artifacts?with_scan_overview=true" \
| jq '.[] | {digest, tags: [.tags[]?.name]}'Trigger a scan for an artifact:
curl -s -u admin:LAB-PASSWORT -X POST "$H/artifacts/1.0.0/scan"Remember: If the repository name contains a slash (
team/demo-app), you have to double-encode it in the URL:team%252Fdemo-app.
skopeo, crane, oras (see Chapters 3 and 4)
skopeo
# Read metadata without pulling the image
skopeo inspect --tls-verify=false docker://localhost:5001/demo-app:1.0.0
# List tags
skopeo list-tags --tls-verify=false docker://localhost:5001/demo-app
# Copy from registry to registry, keeping the digest unchanged
skopeo copy --all --preserve-digests \
--src-tls-verify=false --dest-tls-verify=false \
docker://localhost:5001/demo-app:1.0.0 \
docker://localhost:5002/demo-app:1.0.0
# Write to an OCI archive for transport on physical media
skopeo copy --src-tls-verify=false \
docker://localhost:5001/demo-app:1.0.0 oci-archive:demo-app-1.0.0.tarcrane
crane digest localhost:5001/demo-app:1.0.0 # get the digest
crane ls localhost:5001/demo-app # list tags
crane manifest localhost:5001/demo-app:1.0.0 | jq .
crane config localhost:5001/demo-app:1.0.0 | jq .config.User
crane copy localhost:5001/demo-app:1.0.0 localhost:5002/demo-app:1.0.0
crane pull --format=oci localhost:5001/demo-app:1.0.0 ./oci-layoutFor registries without TLS that are not called
localhost, add --insecure.
oras
# Attach an SBOM to an image as a referrer
oras attach --plain-http --artifact-type application/vnd.cyclonedx+json \
localhost:5001/demo-app@sha256:DIGEST sbom.cdx.json
# Show attached artifacts
oras discover --plain-http localhost:5001/demo-app@sha256:DIGEST
# Copy an image together with its referrers (signatures, SBOM)
oras copy -r --from-plain-http --to-plain-http \
localhost:5001/demo-app@sha256:DIGEST localhost:5002/demo-app:1.0.0
# Store any file as an artifact and fetch it again
oras push --plain-http localhost:5001/bundles/policy:1.0 policy.tar.gz
oras pull --plain-http -o ./out localhost:5001/bundles/policy:1.0openssl: your own PKI (see Chapter 5)
The commands assume OpenSSL 3. The preinstalled LibreSSL on macOS
behaves differently in places; use openssl from Homebrew
there.
Root CA key and self-signed root certificate:
cd ~/seclab/pki/root
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-384 \
-out root.key
openssl req -x509 -new -key root.key -sha384 -days 3650 \
-subj "/CN=Seclab Root CA" \
-addext "basicConstraints=critical,CA:TRUE" \
-addext "keyUsage=critical,keyCertSign,cRLSign" \
-out root.crtIntermediate CA: key and certificate signing request (CSR):
cd ~/seclab/pki/intermediate
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out int.key
openssl req -new -key int.key -subj "/CN=Seclab Signing CA" -out int.csrExtensions in int.ext and signing by the root:
basicConstraints = critical, CA:TRUE, pathlen:0
keyUsage = critical, keyCertSign, cRLSignopenssl x509 -req -in int.csr -CA ../root/root.crt \
-CAkey ../root/root.key -CAcreateserial -days 1825 -sha384 \
-extfile int.ext -out int.crtVerify and display:
openssl verify -CAfile ../root/root.crt int.crt # expected: int.crt: OK
openssl x509 -in int.crt -noout -subject -issuer -dates
openssl x509 -in int.crt -noout -text | grep -A1 'Basic Constraints'
openssl verify -CAfile root.crt -untrusted int.crt leaf.crt # whole chainSecurity: The root key belongs offline (encrypted media, HSM, safe). In the lab it sits unencrypted in the file system; that is acceptable only for practice.
cosign (see Chapter 5)
Generate a key pair (asks for a password; alternatively set
COSIGN_PASSWORD):
cd ~/seclab/kap05
cosign generate-key-pair # creates cosign.key and cosign.pubSign and verify offline, without the public transparency log:
DIGEST=$(crane digest localhost:5001/demo-app:1.0.0)
cosign sign --key cosign.key --tlog-upload=false \
localhost:5001/demo-app@$DIGEST
cosign verify --key cosign.pub --insecure-ignore-tlog=true \
localhost:5001/demo-app@$DIGEST | jq .Attach an SBOM as a signed attestation and verify it:
cosign attest --key cosign.key --tlog-upload=false \
--type cyclonedx --predicate sbom.cdx.json \
localhost:5001/demo-app@$DIGEST
cosign verify-attestation --key cosign.pub --insecure-ignore-tlog=true \
--type cyclonedx localhost:5001/demo-app@$DIGEST > /dev/null && echo OKShow signatures and attachments, transport an image with its signatures offline:
cosign tree localhost:5001/demo-app@$DIGEST
cosign save --dir ./transfer localhost:5001/demo-app@$DIGEST
cosign load --dir ./transfer localhost:5002/demo-appWarning: With cosign v3,
--use-signing-config=falsemay additionally be required. Check withcosign sign --help.
Vault and OpenBao (see Chapter 6)
All vault commands work the same with the OpenBao CLI
bao.
export VAULT_ADDR=http://localhost:8200 VAULT_TOKEN=root # lab only!
vault statusWrite, read and version KV secrets (version 2):
vault kv put secret/demo/db username=app password=LAB-ONLY-123
vault kv get -field=password secret/demo/db
vault kv metadata get secret/demo/db # view versions
vault kv rollback -version=1 secret/demo/db # restore an old versionPolicy with read permission:
path "secret/data/demo/*" {
capabilities = ["read"]
}
vault policy write demo-read demo-read.hclSet up Kubernetes login for Pods:
vault auth enable kubernetes
vault write auth/kubernetes/config \
kubernetes_host=https://kubernetes.default.svc
vault write auth/kubernetes/role/demo \
bound_service_account_names=demo \
bound_service_account_namespaces=demo \
policies=demo-read ttl=1hDynamic credentials and leases:
vault read database/creds/demo-role # short-lived DB account
vault lease revoke -prefix database/creds/demo-role
vault write -f database/rotate-root/demo-db # rotate the DB root passwordExternal Secrets Operator (see Chapter 6)
SecretStore with Vault and Kubernetes login. Since ESO
0.17, v1 is available; older versions use
v1beta1.
apiVersion: external-secrets.io/v1
kind: SecretStore
metadata:
name: vault
namespace: demo
spec:
provider:
vault:
server: http://vault.vault.svc:8200
path: secret
version: v2
auth:
kubernetes:
mountPath: kubernetes
role: demo
serviceAccountRef:
name: demoExternalSecret that refreshes every 15 minutes:
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: db
namespace: demo
spec:
refreshInterval: 15m
secretStoreRef: { name: vault, kind: SecretStore }
target: { name: db-credentials }
data:
- secretKey: password
remoteRef: { key: demo/db, property: password }Check status and force a sync:
kubectl get externalsecret -n demo # STATUS SecretSynced expected
kubectl describe externalsecret db -n demo
kubectl annotate externalsecret db -n demo \
force-sync=$(date +%s) --overwritegitleaks (see Chapter 6)
# Scan the entire Git history
gitleaks detect --source . -v
# Report as JSON, redact secrets in the report
gitleaks detect --source . --redact \
--report-format json --report-path gitleaks.json
# Only staged changes (for a pre-commit hook)
gitleaks protect --staged -v
# Report only new findings compared with a baseline
gitleaks detect --source . --baseline-path gitleaks-baseline.jsonSince gitleaks 8.19 there are also gitleaks git and
gitleaks dir; detect and protect
keep working. You enter known false positives by fingerprint in
.gitleaksignore. Your own rules go in
.gitleaks.toml:
[extend]
useDefault = true
[allowlist]
description = "Testdaten"
paths = ['''tests/fixtures/.*''']syft (see Chapter 7)
# SBOM from the source directory (CycloneDX)
syft dir:. -o cyclonedx-json=sbom.cdx.json
# SBOM from the image, straight from the registry, without a Docker daemon
syft registry:localhost:5001/demo-app:1.0.0 -o spdx-json=sbom.spdx.json
# Several formats in one run
syft localhost:5001/demo-app:1.0.0 \
-o cyclonedx-json=sbom.cdx.json -o spdx-json=sbom.spdx.json
# Quick overview in the terminal
syft localhost:5001/demo-app:1.0.0 -o table
# Convert the format
syft convert sbom.cdx.json -o spdx-json=sbom.spdx.jsongrype (see Chapters 7 and 8)
grype sbom:./sbom.cdx.json # check an SBOM
grype localhost:5001/demo-app:1.0.0 --fail-on high # exit code 1 from HIGH
grype dir:. --only-fixed # only fixable findings
grype sbom:./sbom.cdx.json -o json > grype.json
grype db status # age of the database
grype db update # update the databaseExceptions in .grype.yaml:
ignore:
- vulnerability: CVE-2023-32681
package:
name: requestsOffline operation: fetch the database outside with
grype db update, transfer it, load it inside with
grype db import <datei> and set
GRYPE_DB_AUTO_UPDATE=false.
Dependency-Track API (see Chapter 7)
All calls need an API key in the X-Api-Key header (team
key from Administration > Access Management >
Teams).
Upload an SBOM and create the project if needed:
export DT_KEY=odt_LAB_SCHLUESSEL
curl -s -X POST http://localhost:8080/api/v1/bom \
-H "X-Api-Key: $DT_KEY" \
-F autoCreate=true -F projectName=demo-app -F projectVersion=1.0.0 \
-F [email protected]
# Response: {"token":"<uuid>"}Wait for processing:
curl -s -H "X-Api-Key: $DT_KEY" \
http://localhost:8080/api/v1/bom/token/TOKEN-UUID # {"processing":false}Newer versions also offer
/api/v1/event/token/<uuid> for this.
Look up a project, fetch findings and metrics:
P=$(curl -s -H "X-Api-Key: $DT_KEY" \
'http://localhost:8080/api/v1/project/lookup?name=demo-app&version=1.0.0' \
| jq -r .uuid)
curl -s -H "X-Api-Key: $DT_KEY" \
http://localhost:8080/api/v1/finding/project/$P \
| jq '.[] | {c: .component.name, v: .vulnerability.vulnId,
s: .vulnerability.severity}'
curl -s -H "X-Api-Key: $DT_KEY" \
http://localhost:8080/api/v1/metrics/project/$P/current | jq .Record a triage decision:
curl -s -X PUT http://localhost:8080/api/v1/analysis \
-H "X-Api-Key: $DT_KEY" -H 'Content-Type: application/json' \
-d '{"project":"P-UUID","component":"C-UUID","vulnerability":"V-UUID",
"analysisState":"NOT_AFFECTED",
"analysisJustification":"CODE_NOT_REACHABLE",
"analysisDetails":"Funktion wird nicht aufgerufen",
"isSuppressed":true}'trivy (see Chapter 8)
# Scan an image; the pipeline fails from HIGH
trivy image --severity HIGH,CRITICAL --exit-code 1 --ignore-unfixed \
localhost:5001/demo-app:1.0.0
# Source directory: dependencies and secrets
trivy fs --scanners vuln,secret .
# IaC misconfigurations (Kubernetes, Dockerfile, Terraform)
trivy config k8s/
# Generate an SBOM and scan an SBOM
trivy image --format cyclonedx --output sbom.cdx.json \
localhost:5001/demo-app:1.0.0
trivy sbom sbom.cdx.json
# Result as SARIF for GitLab/IDE
trivy image --format sarif --output trivy.sarif localhost:5001/demo-app:1.0.0Offline operation:
trivy image --download-db-only # outside: fetch the DB
trivy image --skip-db-update --offline-scan IMAGE # inside: no network
trivy image --db-repository reg-build:5000/trivy-db IMAGE # mirrored DBExceptions in .trivyignore, one CVE ID per line, with a
comment and expiry date:
# requests: not reachable, ticket SEC-42, valid until 2026-12-31
CVE-2023-32681
checkov (see Chapter 8)
checkov -d k8s/ --framework kubernetes --compact # scan a directory
checkov -f Dockerfile --framework dockerfile # single file
checkov -d k8s/ --check CKV_K8S_8,CKV_K8S_9 # only specific rules
checkov -d k8s/ --skip-check CKV_K8S_43 # exempt a rule
checkov -d k8s/ --soft-fail # report, do not fail
checkov -d k8s/ -o sarif --output-file-path reports/ # SARIF report
checkov -d . --create-baseline # record existing findings
checkov -d . --baseline .checkov.baseline # only new findings
checkov -d k8s/ --config-file .checkov.yaml # settings from a fileException directly in the Kubernetes manifest, with a justification:
metadata:
name: demo
annotations:
checkov.io/skip1: CKV_K8S_43=Digest wird per Kyverno erzwungensemgrep (see Chapter 8)
semgrep scan --config p/python --metrics=off --error # rule pack, exit 1 on finding
semgrep scan --config .semgrep/ --metrics=off # own rules, offline
semgrep scan --config .semgrep/ --sarif -o semgrep.sarif
semgrep scan --config .semgrep/ --severity ERROR --json -o semgrep.jsonYour own rule (.semgrep/no-debug.yaml):
rules:
- id: flask-debug-enabled
languages: [python]
severity: ERROR
message: Flask läuft mit debug=True
pattern: $APP.run(..., debug=True, ...)Suppress a single finding in the code with a justification:
# nosemgrep: flask-debug-enabled.
Remember: semgrep downloads registry packs like
p/pythonfrom the internet. In air-gapped environments, you store the rules as files.
kyverno CLI (see Chapter 9)
kyverno apply policy.yaml --resource k8s/deployment.yaml # policy against a file
kyverno apply policies/ --resource k8s/deployment.yaml --resource k8s/service.yaml
kyverno test tests/ # run test cases
kubectl get policyreport -A # results in the clusterSimple validation rule (since Kyverno 1.13, alternatively
failureAction inside validate):
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-non-root
spec:
validationFailureAction: Enforce
rules:
- name: run-as-non-root
match:
any:
- resources: { kinds: [Pod] }
validate:
message: "Container müssen als Nicht-root laufen."
pattern:
spec:
securityContext:
runAsNonRoot: trueAdmit only signed images from your own registry:
- name: verify-signature
match:
any:
- resources: { kinds: [Pod] }
verifyImages:
- imageReferences: ["reg-build:5000/*"]
mutateDigest: true
attestors:
- entries:
- keys:
publicKeys: |-
-----BEGIN PUBLIC KEY-----
...contents of cosign.pub...
-----END PUBLIC KEY-----
rekor: { ignoreTlog: true }
ctlog: { ignoreSCT: true }conftest and opa (see Chapter 9)
Policy in policy/deployment.rego (by default, conftest
looks in the main package):
package main
import rego.v1
deny contains msg if {
input.kind == "Deployment"
some c in input.spec.template.spec.containers
not contains(c.image, "@sha256:")
msg := sprintf("Container %s nutzt keinen Digest", [c.name])
}
conftest test k8s/deployment.yaml -p policy/ # check manifests
conftest test Dockerfile -p policy/ --parser dockerfile
conftest test k8s/ -p policy/ -o json # machine-readable
conftest verify -p policy/ # Rego unit testsopa eval -d policy/ -i input.json 'data.main.deny' # single evaluation
opa test policy/ -v # run tests
opa fmt -w policy/ # format
opa fmt --list --fail policy/ # CI: exit 1 if unformatted
opa check policy/ # check syntaxTip:
import rego.v1works from OPA 0.59 onward and remains valid in OPA 1.x. That way the same policy runs on old and new versions.