-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
805e912
commit f4f5358
Showing
17 changed files
with
177 additions
and
16 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,14 @@ | ||
#!/usr/bin/env bash | ||
set -eox pipefail | ||
|
||
. .cicd/env.sh | ||
|
||
docker run --rm \ | ||
-v "$(pwd):/go/src/$mod" \ | ||
-w "/go/src/$mod" \ | ||
-e GO111MODULE=on \ | ||
-e CGO_ENABLED=0 \ | ||
-e GOOS=linux \ | ||
-e GOARCH=amd64 \ | ||
golang:1.12-stretch \ | ||
go build -mod=vendor -ldflags "-X $mod/core.Version=$vers -X $mod/core.BuildTime=$buildTime" |
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,16 @@ | ||
#!/usr/bin/env bash | ||
set -eox pipefail | ||
|
||
. .cicd/env.sh | ||
|
||
command="go fmt ./... && git diff --exit-code;" | ||
|
||
docker run --rm \ | ||
-v "$(pwd):/go/src/$mod" \ | ||
-w "/go/src/$mod" \ | ||
-e GO111MODULE=on \ | ||
-e CGO_ENABLED=0 \ | ||
-e GOOS=linux \ | ||
-e GOARCH=amd64 \ | ||
golang:1.12-stretch \ | ||
/bin/bash -c "$command" |
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,7 @@ | ||
#!/usr/bin/env bash | ||
set -eox pipefail | ||
|
||
. .cicd/env.sh | ||
|
||
docker build . -t $dockerRepo:$vers | ||
docker run --rm $dockerRepo:$vers version |
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,26 @@ | ||
#!/usr/bin/env bash | ||
set -eox pipefail | ||
|
||
export dockerRepo="jettech/kube-webhook-certgen" | ||
export mod="$(head -n 1 go.mod | cut -f 2 -d ' ')" | ||
export rev=$(git rev-parse HEAD) | ||
export tag=$(git tag --points-at HEAD) | ||
export buildTime=$(date -u +%FT%TZ) | ||
|
||
# This will break if there are multiple tags set to the same commit, which is what we want | ||
if [ $tag ]; then | ||
export vers=$tag | ||
export isTag=true | ||
else | ||
export vers=$rev | ||
export isTag=false | ||
fi | ||
|
||
# Azure pipelines requires this invocation to set variables to be available in later steps | ||
# And then you have to retrieve them in a similar interpolation fashion - i.e. they are _not_ | ||
# environment variables | ||
echo "##vso[task.setvariable variable=dockerRepo]$dockerRepo" | ||
echo "##vso[task.setvariable variable=mod]$mod" | ||
echo "##vso[task.setvariable variable=rev]$rev" | ||
echo "##vso[task.setvariable variable=vers]$vers" | ||
echo "##vso[task.setvariable variable=isTag]$isTag" |
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,29 @@ | ||
name: $(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r) | ||
pr: none | ||
trigger: | ||
branches: | ||
include: | ||
- master | ||
- refs/tags/* | ||
pool: | ||
vmImage: 'ubuntu-latest' | ||
steps: | ||
- script: .cicd/checks.sh | ||
displayName: 'Checks' | ||
- script: .cicd/test.sh | ||
displayName: 'Test' | ||
- task: PublishTestResults@2 | ||
displayName: 'Publish Test Results' | ||
inputs: | ||
testResultsFormat: 'JUnit' | ||
testResultsFiles: '**/TEST-*.xml' | ||
failTaskOnFailedTests: true | ||
- script: .cicd/build.sh | ||
displayName: 'Build' | ||
- script: .cicd/docker.sh | ||
displayName: 'Docker Build' | ||
- script: .cicd/push.sh | ||
env: | ||
jettechPassword: $(jettechPassword) | ||
displayName: 'Docker Push' | ||
condition: startsWith(variables['isTag'], 'true') |
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,22 @@ | ||
name: $(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r) | ||
trigger: | ||
branches: | ||
include: | ||
- refs/pull/* | ||
pool: | ||
vmImage: 'ubuntu-latest' | ||
steps: | ||
- script: .cicd/checks.sh | ||
displayName: 'Checks' | ||
- script: .cicd/test.sh | ||
displayName: 'Test' | ||
- task: PublishTestResults@2 | ||
inputs: | ||
testResultsFormat: 'JUnit' | ||
testResultsFiles: '**/TEST-*.xml' | ||
failTaskOnFailedTests: true | ||
- script: .cicd/build.sh | ||
displayName: 'Build' | ||
- script: .cicd/docker.sh | ||
displayName: 'Docker Build' | ||
condition: lt(variables['System.PullRequest.PullRequestId'], 1) |
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,16 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail | ||
|
||
. .cicd/env.sh | ||
|
||
function exists() { | ||
curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 > /dev/null | ||
} | ||
|
||
if exists $dockerRepo $vers; then | ||
echo $dockerRepo:$vers already exists, will not overwrite | ||
exit 1 | ||
else | ||
docker login -u jettech -p $jettechPassword | ||
docker push $dockerRepo:$vers | ||
fi |
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,17 @@ | ||
#!/usr/bin/env bash | ||
set -eox pipefail | ||
|
||
. .cicd/env.sh | ||
|
||
command="go get -u github.com/jstemmer/go-junit-report; \ | ||
go test -mod=vendor -v ./... 2>&1 | go-junit-report > TEST-ALL.xml" | ||
|
||
docker run --rm \ | ||
-v "$(pwd):/go/src/$mod" \ | ||
-w "/go/src/$mod" \ | ||
-e GO111MODULE=on \ | ||
-e CGO_ENABLED=0 \ | ||
-e GOOS=linux \ | ||
-e GOARCH=amd64 \ | ||
golang:1.12-stretch \ | ||
/bin/bash -c "$command" |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
.idea | ||
kube-webhook-certgen | ||
TEST-ALL.xml |
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 |
---|---|---|
@@ -1,13 +1,3 @@ | ||
FROM golang:1.12-alpine AS build | ||
ARG VERSION=0.0.0 | ||
ARG PACKAGE="github.com/jet/kube-webhook-certgen" | ||
WORKDIR /go/src/${PACKAGE} | ||
COPY . . | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ | ||
go build -o kube-webhook-certgen -ldflags \ | ||
"-X ${PACKAGE}/core.Version=${VERSION} -X ${PACKAGE}/core.BuildTime=$(date -u +%FT%TZ)" | ||
RUN mv kube-webhook-certgen /kube-webhook-certgen | ||
|
||
FROM gcr.io/distroless/base | ||
COPY --from=build /kube-webhook-certgen /kube-webhook-certgen | ||
COPY kube-webhook-certgen /kube-webhook-certgen | ||
ENTRYPOINT ["/kube-webhook-certgen"] |
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 |
---|---|---|
@@ -1,7 +1,21 @@ | ||
[![Build Status](https://dev.azure.com/jet-opensource/opensource/_apis/build/status/kube-webhook-certgen/kube-webhook-certgen.master?branchName=master)](https://dev.azure.com/jet-opensource/opensource/_build/latest?definitionId=15&branchName=master) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/jet/kube-webhook-certgen)](https://goreportcard.com/report/github.com/jet/kube-webhook-certgen) | ||
[![Docker Pulls](https://img.shields.io/docker/pulls/jettech/kube-webhook-certgen.svg)](https://hub.docker.com/r/jettech/kube-webhook-certgen) | ||
|
||
# Kubernetes webhook certificate generator and patcher | ||
|
||
This utility has two functions | ||
|
||
## Purpose | ||
This is a utility to generate certificates with long (100y) expiration, then patch Kubernetes Admission Webhooks with the CA. It is intended to provide a minimal solution for getting admission hooks working. | ||
|
||
This tool has two functions | ||
1. Create a ca, certificate and key and store them in a secret. If the secret already exists, do nothing | ||
2. Use the secret data to patch a mutating and validating webhook ca field | ||
2. Use the secret data to patch a mutating and validating webhook `ca` field | ||
|
||
The two-part approach is to allow easier working with helm charts, to first provision the certs, then patch the hooks after they are created with helm. If you have an alternative means of creating the certificaes, the tool can still be used to patch the webhooks. | ||
|
||
For more information about admission hooks see the [Kubernetes documentation](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/) | ||
|
||
## Security Considerations | ||
This tool may not be adequate in all security environments. If a more complete solution is required, you may want to seek alternatives such as [jetstack/cert-manager](https://github.com/jetstack/cert-manager) | ||
|
||
This is broken into two parts to allow easier working with helm charts, to first provision the certs, then patch the hooks after they are created with helm. This is an alternative to using [jetstack/cert-manager](https://github.com/jetstack/cert-manager). |
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
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
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
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
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
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