-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of kerberos sidecar injector
- Loading branch information
0 parents
commit 1e9f38b
Showing
21 changed files
with
1,563 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
vendor/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# This workflow will build a docker container, publish it to Azure Container Registry, and deploy it to Azure Kubernetes Service using a helm chart. | ||
# | ||
# https://github.com/Azure/actions-workflow-samples/tree/master/Kubernetes | ||
# | ||
# To configure this workflow: | ||
# | ||
# 1. Set up the following secrets in your workspace: | ||
# a. REGISTRY_USERNAME with ACR username | ||
# b. REGISTRY_PASSWORD with ACR Password | ||
# | ||
# 2. Change the values for the REGISTRY_NAME environment variables (below). | ||
name: build | ||
on: | ||
pull_request: | ||
types: | ||
- 'opened' | ||
- 'synchronize' | ||
- 'reopened' | ||
|
||
# Environment variables available to all jobs and steps in this workflow | ||
env: | ||
REGISTRY_NAME: k8scc01covidacr | ||
TRIVY_VERSION: "v0.58.2" | ||
TRIVY_DATABASES: '"ghcr.io/aquasecurity/trivy-db:2","public.ecr.aws/aquasecurity/trivy-db"' | ||
TRIVY_JAVA_DATABASES: '"ghcr.io/aquasecurity/trivy-java-db:1","public.ecr.aws/aquasecurity/trivy-java-db"' | ||
TRIVY_MAX_RETRIES: 5 | ||
TRIVY_RETRY_DELAY: 20 | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
services: | ||
registry: | ||
image: registry:2 | ||
ports: | ||
- 5000:5000 | ||
steps: | ||
- uses: actions/checkout@master | ||
|
||
# Connect to Azure Container registry (ACR) | ||
- uses: azure/docker-login@v1 | ||
with: | ||
login-server: ${{ env.REGISTRY_NAME }}.azurecr.io | ||
username: ${{ secrets.REGISTRY_USERNAME }} | ||
password: ${{ secrets.REGISTRY_PASSWORD }} | ||
|
||
# Container build | ||
- run: | | ||
docker build -f Dockerfile -t localhost:5000/kerberos-injector:${{ github.sha }} . | ||
docker push localhost:5000/kerberos-injector:${{ github.sha }} | ||
docker image prune | ||
# Scan image for vulnerabilities | ||
- name: Aqua Security Trivy image scan | ||
run: | | ||
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin ${{ env.TRIVY_VERSION }} | ||
set +e # Lets trivy return an error without it being fatal | ||
for ((i=0; i<${{ env.TRIVY_MAX_RETRIES }}; i++)); do | ||
echo "Attempt $((i + 1)) of ${{ env.TRIVY_MAX_RETRIES }}..." | ||
trivy image \ | ||
--db-repository ${{ env.TRIVY_DATABASES }} \ | ||
--java-db-repository ${{ env.TRIVY_JAVA_DATABASES }} \ | ||
localhost:5000/kerberos-injector:${{ github.sha }} \ | ||
--exit-code 10 --timeout=20m --scanners vuln --severity CRITICAL | ||
EXIT_CODE=$? | ||
if [[ $EXIT_CODE -eq 0 ]]; then | ||
echo "Trivy scan completed successfully." | ||
exit 0 | ||
elif [[ $EXIT_CODE -eq 10 ]]; then | ||
echo "Trivy scan completed successfully. Some vulnerabilities were found." | ||
exit 10 | ||
elif [[ $i -lt $(( ${{ env.TRIVY_MAX_RETRIES }} - 1)) ]]; then | ||
echo "Encountered unexpected error. Retrying in ${{ env.TRIVY_RETRY_DELAY }} seconds..." | ||
sleep ${{ env.TRIVY_RETRY_DELAY }} | ||
else | ||
echo "Unexpected error persists after ${{ env.TRIVY_MAX_RETRIES }} attempts. Exiting." | ||
exit 1 | ||
fi | ||
done | ||
- name: Test if we should push to ACR | ||
id: should-i-push | ||
if: | | ||
github.event_name == 'push' || | ||
( | ||
github.event_name == 'pull_request' && | ||
contains( github.event.pull_request.labels.*.name, 'auto-deploy') | ||
) | ||
run: echo 'boolean=true' >> $GITHUB_OUTPUT | ||
|
||
- name: Push image to registry | ||
if: steps.should-i-push.outputs.boolean == 'true' | ||
run: | | ||
docker pull localhost:5000/kerberos-injector:${{ github.sha }} | ||
docker tag localhost:5000/kerberos-injector:${{ github.sha }} ${{ env.REGISTRY_NAME }}.azurecr.io/kerberos-injector:${{ github.sha }} | ||
docker push ${{ env.REGISTRY_NAME }}.azurecr.io/kerberos-injector:${{ github.sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# This workflow: | ||
# * Builds, tests, and scans all images | ||
# * (optionally) pushes the images to ACR | ||
# | ||
# | ||
# This workflow triggers on: | ||
# * a push to main | ||
# | ||
# Image build/test/scan will run on any of the above events. | ||
# Image push will run only if: | ||
# * this is a push to main | ||
# | ||
# To configure this workflow: | ||
# | ||
# 1. Set up the following secrets in your workspace: | ||
# a. REGISTRY_USERNAME with ACR username | ||
# b. REGISTRY_PASSWORD with ACR Password | ||
# | ||
# 2. Change the values for the REGISTRY_NAME | ||
name: build_and_push | ||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
|
||
jobs: | ||
# Any checks that run pre-build | ||
pre-build-checks: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
build-push: | ||
env: | ||
REGISTRY_NAME: k8scc01covidacr | ||
LOCAL_REPO: localhost:5000 | ||
TRIVY_VERSION: "v0.57.0" | ||
TRIVY_DATABASES: '"ghcr.io/aquasecurity/trivy-db:2","public.ecr.aws/aquasecurity/trivy-db"' | ||
TRIVY_JAVA_DATABASES: '"ghcr.io/aquasecurity/trivy-java-db:1","public.ecr.aws/aquasecurity/trivy-java-db"' | ||
TRIVY_MAX_RETRIES: 5 | ||
TRIVY_RETRY_DELAY: 20 | ||
needs: pre-build-checks | ||
runs-on: ubuntu-latest | ||
services: | ||
registry: | ||
image: registry:2 | ||
ports: | ||
- 5000:5000 | ||
steps: | ||
|
||
- uses: actions/checkout@master | ||
|
||
# Connect to Azure Container registry (ACR) | ||
- uses: azure/docker-login@v1 | ||
with: | ||
login-server: ${{ env.REGISTRY_NAME }}.azurecr.io | ||
username: ${{ secrets.REGISTRY_USERNAME }} | ||
password: ${{ secrets.REGISTRY_PASSWORD }} | ||
|
||
- name: Build image | ||
id: build-image | ||
run: | | ||
docker build -f Dockerfile -t localhost:5000/kerberos-injector:latest . | ||
docker push localhost:5000/kerberos-injector:latest | ||
docker image prune | ||
# Scan image for vulnerabilities | ||
- name: Aqua Security Trivy image scan | ||
run: | | ||
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin ${{ env.TRIVY_VERSION }} | ||
set +e # Lets trivy return an error without it being fatal | ||
for ((i=0; i<${{ env.TRIVY_MAX_RETRIES }}; i++)); do | ||
echo "Attempt $((i + 1)) of ${{ env.TRIVY_MAX_RETRIES }}..." | ||
trivy image \ | ||
--db-repository ${{ env.TRIVY_DATABASES }} \ | ||
--java-db-repository ${{ env.TRIVY_JAVA_DATABASES }} \ | ||
localhost:5000/kerberos-injector:latest \ | ||
--exit-code 10 --timeout=20m --scanners vuln --severity CRITICAL | ||
EXIT_CODE=$? | ||
if [[ $EXIT_CODE -eq 0 ]]; then | ||
echo "Trivy scan completed successfully." | ||
exit 0 | ||
elif [[ $EXIT_CODE -eq 10 ]]; then | ||
echo "Trivy scan completed successfully. Some vulnerabilities were found." | ||
exit 0 | ||
elif [[ $i -lt $(( ${{ env.TRIVY_MAX_RETRIES }} - 1)) ]]; then | ||
echo "Encountered unexpected error. Retrying in ${{ env.TRIVY_RETRY_DELAY }} seconds..." | ||
sleep ${{ env.TRIVY_RETRY_DELAY }} | ||
else | ||
echo "Unexpected error persists after ${{ env.TRIVY_MAX_RETRIES }} attempts. Exiting." | ||
exit 1 | ||
fi | ||
done | ||
- name: Push image to registry | ||
run: | | ||
docker pull localhost:5000/kerberos-injector:latest | ||
docker tag localhost:5000/kerberos-injector:latest ${{ env.REGISTRY_NAME }}.azurecr.io/kerberos-injector:${{ github.sha }} | ||
docker push ${{ env.REGISTRY_NAME }}.azurecr.io/kerberos-injector:${{ github.sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
vendor/* | ||
|
||
build/_output | ||
|
||
# GOPATH | ||
.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Build the sidecar-injector binary | ||
FROM golang:1.22 AS builder | ||
|
||
WORKDIR /workspace | ||
# Copy the Go Modules manifests | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
# cache deps before building and copying source so that we don't need to re-download as much | ||
# and so that source changes don't invalidate our downloaded layer | ||
RUN go mod download | ||
|
||
# Copy the go source | ||
COPY cmd/ cmd/ | ||
|
||
# Build | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o kerberos-sidecar-injector ./cmd | ||
|
||
|
||
FROM alpine:latest | ||
|
||
# install curl for prestop script | ||
RUN apk --no-cache add curl | ||
|
||
WORKDIR / | ||
|
||
# install binary | ||
COPY --from=builder /workspace/kerberos-sidecar-injector . | ||
|
||
USER 65532:65532 | ||
|
||
ENTRYPOINT ["/kerberos-sidecar-injector"] |
Oops, something went wrong.