Introduction
When configuring the Vault GitHub Action, one thing that commonly needs done is configuring a CA Certificate within GitHub so that TLS communication to the Vault Server can occur successfully. This can be a bit tricky to setup if it is your first time doing so, so we will walk through it.
Procedure
Firstly, if just getting started with the Vault GitHub Action, then this tutorial is a great place to start and understand the basics of implementation. The GitHub Action is configured using YAML. An example usage of this configuration can be found below.
jobs: build: # ... steps: # ... - name: Import Secrets uses: hashicorp/vault-action@v2.4.0 with: url: https://vault.mycompany.com:8200 token: ${{ secrets.VAULT_TOKEN }} caCertificate: ${{ secrets.VAULT_CA_CERT }} secrets: | secret/data/ci/aws accessKey | AWS_ACCESS_KEY_ID ; secret/data/ci/aws secretKey | AWS_SECRET_ACCESS_KEY ; secret/data/ci npm_token
As you can see, the caCertificate
input is being set to the ${{ secrets.VAULT_CA_CERT }}
. This correlates to a secret which you configure in your GitHub repository called VAULT_CA_CERT
. When you're wondering what to set the VAULT_CA_CERT
secret to, you can refer to the GitHub input reference here. As per the input reference, the value of caCertificate
should be: "Base64 encoded CA certificate the server certificate was signed with".
Let's break this down and evaluate it. Firstly, your CA certificate should be your entire CA chain. The CA chain represents the entire chain of trust associated with your certificate. This means that you can't simply configure this value to be the root CA, you must have the entire chain. The chain should include certificates appended one after another. A certificate chain with 2 certificates in it would look like the following.
-----BEGIN CERTIFICATE-----
MIIDsDCCApigAwIBAgIUf/c3nJZIu6W4BliUlq2TjMWI4t4wDQYJKoZIhvcNAQEL
BQAwFjEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMjIwNDA4MTgzMjU2WhcNMjcw
NDA3MgzMzI2WjAtMSswKQYDVQQDEyJleGFtcGxlLmNvbSBJbnRlcm1lZGlhdGUg
QXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzHuw/57F
Vhp+Ku3EPjb0xMB+UEKNSq1Kj/yAbQAq1hMymNk/WvqCcijG2Y3nkwBMRVK6Xx/G
T7lzhx3L4Q1Gb44A1MkRZrLbjUs42u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jb20wHhcNMjIwNDA4MTgzMjUxWhcNMzIw
NDA1MTgzMzIxWjAWMRQwEgYDVQQDEwtleGFtcGxlLmNvbTCCASIwDQYJKoZIhvcN
AQEBBQADggEPADCCAQoCggEBAMbO+c5c59+qA1xQRSfGZPF83vK4cb0E5jQArkXg
MdCYe9YNfyc4/ecqjGFsDW6tTrqjmSJsa6jJmh20qUkPYXyS01MlOsyPLt9kKBgU
shnlKAI0jJV0iwoIldS/3A4wXQgeDwLrEb2AXHdO6qlFPZnUB8IxquVqF0t0S2w8
vPG3YuO2mE70V8J9YqMYA1LiNueLGm2VRZNnKE4jUGqMDhlryYehgJWagvO0juQf
Y/H3Ltm3g+aYqVIMS3tp+iijtg2XfEjoGdjd5oNbmO77RQonomWInDr2a2zLIexh
fGnDo/VpomfJgOLWmrpMEweaui42HjTFbcTQO2weuGInpwUCAwEAAaN7MHkwDgYD
VR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFIXjvTnrBuat
nf5rISkMfVkiJk3PMB8GA1UdIwQYMBaAFIXjvTnrBuatnf5rISkMfVkiJk3PMBYG
A1UdEQQPMA2CC2V4YW1wbGUuY29tMA0GCSqGSIb3DQEBCwUAA4IBAQCmdF855g8T
W2vneKWmmXD2LKMFFaGr67ySNMUs5+6fBSOBpqAzWR8/1ZEspZqT1mTflIJIbXxv
Ze9E6fjtYXbdSUu70EUc5JF/25PyfWwcbBvN4f+f+bPweaRiVaarOp9O4pDsZHDY
Yvz1cpOmspqDZZ3bgmp77G6w/0E132k8cQrEmHVBmDc+OeAc49cwqTIcpIiYJiVQ
UGLIbJkkC4MJgUBKK5nRw0VOryNpknWVV18lpRIlo0Tf3TECrR8OkXGOFziJVuUK
c2nRMAlYi8TdqRsYWTac+smui70vqrZGGcgohFjPjWGmh5S5zDFZO5R1mEbgrp
aPQ3/XYN9vZd
-----END CERTIFICATE-----
Once you have your certificate chain in the correct order in a file, you can then tackle the last requirement - base64 encoding the chain. This part is pretty simple. You can cat
out the file and pipe it into the base64
utility to get a resultant base64 encoded certificate chain. The process looks like the following.
$ cat vault-ca.crt | base64
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURzRENDQXBpZ0F3SUJBZ0lVZi9jM25KWkl1
Nlc0QmxpVWxxMlRqTVdJNHQ0d0RRWUpLb1pJaHZjTkFRRUwKQlFBd0ZqRVVNQklHQTFVRUF4TUxa
WGhoYlhCc1pTNWpiMjB3SGhjTk1qSXdOREE0TVRnek1qVTJXaGNOTWpjdwpOREEzTVRnek16STJX
akF0TVNzd0tRWURWUVFERXlKbGVHRnRjR3hsTG1OdmJTQkpiblJsY20xbFpHbGhkR1VnClFYVjBh
Rzl5YVhSNU1JSUJJakFOQmdrcWhraUc5dzBCQVFFRkFBT0NBUThBTUlJQkNnS0NBUUVBekh1dy81
N0YKVmhwK0t1M0VQamIweE1CK1VFS05TcTFLai95QWJRQXExaE15bU5rL1d2cUNjaWpHMlkzbmt3
Qk1SVks2WHgvRwpUN2x6aHgzTDRRMUdiNDRBMU1rUlpyTGJqVXM0MnVPd2tocXJCMXVzSDBVYy90
RU1rb2xRM21Ob0V1aXVQeGdsCjdwRWhHRDNvMnlZaXFER0JrN05sRzhNa2QrSnh6QnB3emUxLy9V
TXVZYnVBNTVRWUZPVm5INjlNVUVhVEJGaDUKa3RzYjl5Q21YZmpTeUxWNXp6VURFb21USWttQldB
bWF6WHVnbm9jUkx2VWR0bENBVmVVTXIwZWMzSXJ3ZjN4QQpUeG5IZlJPc0x3bG90anlmaVRKdHZJ
RVZ5a0tyV0xnSytrNkNKUkZidVJaQTlJYUZkRmliSG1sanAyOFV6SmswCkhxRk9INXhNTVpzWk93
SURBUUFCbzRIZU1JSGJNQTRHQTFVZER3RUIvd1FFQXdJQkJqQVBCZ05WSFJNQkFmOEUKQlRBREFR
SC9NQjBHQTFVZERnUVdCQlJYRnB4RFFYdDV5MHVIVVZaeWdNbEF6ZmJRY1RBZkJnTlZIU01FR0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HNncvMEUxMzJrOGNRckVtSFZCbURjK09lQWM0OWN3cVRJY3BJaVlK
aVZRClVHTEliSmtrQzRNSmdVQktLNW5SdzBWT3J5TnBrbldWVjE4bHBSSWxvMFRmM1RFQ3JSOE9r
WEdPRnppSlZ1VUsKYzJuUk11QWxZaThUZHFSc1lXVGFjK3NtdWk3MHZxclpHR2Nnb2hGalBqV0dt
aDVTNXpERlpPNVIxbUVoYmdycAphUFEzL1hZTjl2WmQKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0t
LQo=
Once you have the base64 string, the last step is to copy that string exactly as it is into your VAULT_CA_CERT
GitHub secret. Then your YAML template will reference that secret and assign it's value to the caCertificate
input, and that's it!