diff --git a/Jenkinsfile b/Jenkinsfile index 76f80bf..b6d91a1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,5 @@ #!/usr/bin/env groovy + /* Copyright 2018 Google LLC @@ -22,93 +23,75 @@ limitations under the License. // Reference: https://github.com/jenkinsci/kubernetes-plugin // set up pod label and GOOGLE_APPLICATION_CREDENTIALS (for Terraform) -def label = "k8s-infra" -def containerName = "k8s-node" -def GOOGLE_APPLICATION_CREDENTIALS = '/home/jenkins/dev/jenkins-deploy-dev-infra.json' +def containerName = "vault" +def GOOGLE_APPLICATION_CREDENTIALS = '/home/jenkins/dev/jenkins-deploy-dev-infra.json' // Tells the ./scripts/common.sh which VAULT_VERSION of the vault CLI binary to use -def VAULT_VERSION = '1.0.2' - -podTemplate(label: label, yaml: """ -apiVersion: v1 -kind: Pod -metadata: - labels: - jenkins: build-node -spec: - containers: - - name: ${containerName} - image: gcr.io/pso-helmsman-cicd/jenkins-k8s-node:${env.CONTAINER_VERSION} - command: ['cat'] - tty: true - volumeMounts: - # Mount the dev service account key - - name: dev-key - mountPath: /home/jenkins/dev - # Mount the host /dev/urandom to /dev/random for entropy - - name: random - mountPath: /dev/random - volumes: - # Create a volume that contains the dev json key that was saved as a secret - - name: dev-key - secret: - secretName: jenkins-deploy-dev-infra - # Host /dev/urandom to allow for entropy access - - name: random - hostPath: - path: /dev/urandom -""" - ) { - node(label) { - try { - // Options covers all other job properties or wrapper functions that apply to entire Pipeline. - properties([disableConcurrentBuilds()]) - // set env variable GOOGLE_APPLICATION_CREDENTIALS for Terraform - env.GOOGLE_APPLICATION_CREDENTIALS=GOOGLE_APPLICATION_CREDENTIALS +def VAULT_VERSION = '1.2.0' +def jenkins_container_version = env.JENKINS_CONTAINER_VERSION - stage('Setup') { - container(containerName) { - // checkout code from scm i.e. commits related to the PR - checkout scm - - // Setup gcloud service account access - sh "gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}" - sh "gcloud config set compute/zone ${env.ZONE}" - sh "gcloud config set core/project ${env.PROJECT_ID}" - sh "gcloud config set compute/region ${env.REGION}" - } - } - stage('Lint') { - container(containerName) { - sh "make lint" - } - } +podTemplate( + containers: [ + containerTemplate(name: "${containerName}", + image: "gcr.io/pso-helmsman-cicd/jenkins-k8s-node:${jenkins_container_version}", + command: 'tail -f /dev/null', + resourceRequestCpu: '1000m', + resourceLimitCpu: '2000m', + resourceRequestMemory: '1Gi', + resourceLimitMemory: '2Gi' + ) + ], + volumes: [secretVolume(mountPath: '/home/jenkins/dev', + secretName: 'jenkins-deploy-dev-infra' + ), + hostPathVolume(mountPath: '/dev/random', hostPath: '/dev/urandom') + ] +) { + node(POD_LABEL) { + try { + // Options covers all other job properties or wrapper functions that apply to entire Pipeline. + properties([disableConcurrentBuilds()]) + // set env variable GOOGLE_APPLICATION_CREDENTIALS for Terraform + env.GOOGLE_APPLICATION_CREDENTIALS = GOOGLE_APPLICATION_CREDENTIALS - stage('Create') { - container(containerName) { - sh "make create" - } - } + stage('Setup') { + container(containerName) { + // checkout code from scm i.e. commits related to the PR + checkout scm - stage('Validate') { - container(containerName) { - sh "make validate" + // Setup gcloud service account access + sh "gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}" + sh "gcloud config set compute/zone ${env.ZONE}" + sh "gcloud config set core/project ${env.PROJECT_ID}" + sh "gcloud config set compute/region ${env.REGION}" + } + } + stage('Lint') { + container(containerName) { + sh "make lint" + } + } + stage('Create') { + container(containerName) { + sh "make create" + } + } + stage('Validate') { + container(containerName) { + sh "make validate" + } + } + } catch (err) { + // if any exception occurs, mark the build as failed + // and display a detailed message on the Jenkins console output + currentBuild.result = 'FAILURE' + echo "FAILURE caught echo ${err}" + throw err + } finally { + stage('Teardown') { + container(containerName) { + sh "make teardown" + } + } } } - - } - catch (err) { - // if any exception occurs, mark the build as failed - // and display a detailed message on the Jenkins console output - currentBuild.result = 'FAILURE' - echo "FAILURE caught echo ${err}" - throw err - } - finally { - stage('Teardown') { - container(containerName) { - sh "make teardown" - } - } - } - } -} +} \ No newline at end of file diff --git a/README.md b/README.md index decc95b..cc267b8 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ Recovery Seal Type shamir Sealed false Total Recovery Shares 1 Threshold 1 -Version 1.0.0 +Version 1.2.0 Cluster Name vault-cluster-be7094aa Cluster ID ac0d2d33-61db-a06a-77d0-eb9c1e87b236 HA Enabled true @@ -136,6 +136,12 @@ HA Cluster https://10.24.1.3:8201 HA Mode active ``` +Enable the `kv` store inside Vault: + +```console +vault secrets enable -path=secret/ kv +``` + Create a sample secret in Vault inside the custom `kv` path: ```console @@ -181,7 +187,7 @@ Recovery Seal Type shamir Sealed false Total Recovery Shares 1 Threshold 1 -Version 1.0.0 +Version 1.2.0 Cluster Name vault-cluster-be7094aa Cluster ID ac0d2d33-61db-a06a-77d0-eb9c1e87b236 HA Enabled true @@ -320,7 +326,7 @@ Recovery Seal Type shamir Sealed false Total Recovery Shares 1 Threshold 1 -Version 1.0.0 +Version 1.2.0 Cluster Name vault-cluster-be7094aa Cluster ID ac0d2d33-61db-a06a-77d0-eb9c1e87b236 HA Enabled true diff --git a/k8s-manifests/sidecar.yaml b/k8s-manifests/sidecar.yaml index 37dc0b5..51e95e4 100644 --- a/k8s-manifests/sidecar.yaml +++ b/k8s-manifests/sidecar.yaml @@ -51,7 +51,7 @@ spec: # The vault-authenticator container authenticates the container using the # kubernetes auth method and puts the resulting token on the filesystem. - name: vault-authenticator - image: registry.hub.docker.com/sethvargo/vault-kubernetes-authenticator:0.1.0 + image: registry.hub.docker.com/sethvargo/vault-kubernetes-authenticator:0.3.0 imagePullPolicy: Always volumeMounts: # The mount where the vault token will be written after login diff --git a/scripts/auth-to-vault.sh b/scripts/auth-to-vault.sh index 017d55b..c7d6cc9 100755 --- a/scripts/auth-to-vault.sh +++ b/scripts/auth-to-vault.sh @@ -99,6 +99,9 @@ vault write auth/kubernetes/config \ kubernetes_ca_cert="${K8S_CACERT}" \ token_reviewer_jwt="${TR_ACCOUNT_TOKEN}" +# Enable the KV secrets backend +vault secrets enable -path=secret/ kv + # Create a policy to be referenced by a role to access the kv location secret/myapp/* vault policy write myapp-kv-rw - <