Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SSL connection to Vault api #50

Merged
merged 13 commits into from
Oct 17, 2024
Merged
21 changes: 19 additions & 2 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
VAULT_CREATE_ROOT: true
VAULT_ROOT_CA_MOUNT: pki
VAULT_ROOT_CA_REF: root-ca
# VAULT_SSL_CERT: cert/vault.pem
JWT_SIGNING_KEY: jwt_secret
APP_REGISTRY_ADDR: http://app_registry:8800
APP_REGISTRY_TOKEN: app_reg_token
Expand All @@ -25,10 +26,26 @@ services:
image: hashicorp/vault:latest
restart: unless-stopped
ports:
- 8200:8200
- 8200:8443
volumes:
- ../cert:/vault/cert
environment:
VAULT_DEV_ROOT_TOKEN_ID: root_token
VAULT_DEV_LISTEN_ADDRESS: 0.0.0.0:8200
VAULT_LOCAL_CONFIG: >
{
"listener": [
{
"tcp": {
"address": "0.0.0.0:8443",
"tls_disable": "1",
"tls_cert_file": "/vault/cert/vault.pem",
"tls_key_file": "/vault/cert/vault.key"
}
}
],
"default_lease_ttl": "168h",
"max_lease_ttl": "720h"
}

app_registry:
image: node:latest
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,32 @@ docker build -t astral:latest .
```
docker run -p 3000:3000 astral:latest
```

# Configuration
Astral is configured in `config/astral.yml` -- all availble
configuration options are listed in the `shared` section. Note that
configuration values can be supplied in this file or as process
environment variables with the same names (but
UPPER_CASE). Environment vars will override any values in the config
file. Per-environment settings in the config file(development, test,
production) will override the shared values for that type.

## mTLS connections
Astral can connect to Vault with mTLS. Just
set the following values in `config/astral.yml`:
```
vault_ssl_cert:
vault_ssl_client_cert:
vault_ssl_client_key:
```
A self-signed server cert for Vault can be generated with the following
command:
```
rake configure:ssl
```

To use in the devcontainer, edit `.devcontainer/docker-compose.yml` so
that the `app` service has `VAULT_ADDRESS` of `https://vault:8200` and
the `VAULT_SSL_CERT` value is uncommented. Finally, the `vault`
service needs `tls_disable` in the `VAULT_LOCAL_CONFIG` set to
`0`. Restart.
17 changes: 16 additions & 1 deletion app/lib/clients/vault.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,29 @@ class << self
def client
::Vault::Client.new(
address: address,
token: token
token: token,
ssl_ca_cert: ssl_cert,
ssl_pem_file: ssl_client_cert,
ssl_key_file: ssl_client_key
)
end

def address
Config[:vault_addr]
end

def ssl_cert
Config[:vault_ssl_cert]
end

def ssl_client_cert
Config[:vault_ssl_client_cert]
end

def ssl_client_key
Config[:vault_ssl_client_key]
end

def enable_engine(mount, type)
client.sys.mount(mount, type, "#{type} secrets engine")
end
Expand Down
Empty file added cert/.keep
GeorgeJahad marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
27 changes: 27 additions & 0 deletions cert/vault.csr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN CERTIFICATE REQUEST-----
MIIElzCCAn8CAQAwUjELMAkGA1UEBhMCVVMxDzANBgNVBAgMBkRlbmlhbDEUMBIG
A1UEBwwLU3ByaW5nZmllbGQxDDAKBgNVBAoMA0RpczEOMAwGA1UEAwwFdmF1bHQw
ggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC4GT1p/wZyxvMsZ/N7g6Hb
SNqTCA6W+JbPryhy2YjVwdH+JwYQGy4GbXYxbKZp5ZXAf5/9/y6j8BnsHrxv5pvC
Ob08aArhQE6ht0NTqaIYsSf/7TeW1e+da5ikLbrcFUcXVzKWtZPcbz4Y42G1AS9T
Lyyw01y6LUGK5WWy3ztD/8fyYVImG7q+8JGYKJpxI0fsLaEpDvHq5ZpOPMJqT0tb
aWwK8CtDcLEjv1bxmXUpD6c8FzffRwuy1SM6USMyAFFLdIVizjgekhRJPOQTeO8N
y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8rKxcvAmdbic4ygg7MfRhnT/B4HFSKKyoU
JCy4FPyt1+iqfDzjtS74h261lVm6bHnW+7bI
-----END CERTIFICATE REQUEST-----
52 changes: 52 additions & 0 deletions cert/vault.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQC4GT1p/wZyxvMs
Z/N7g6HbSNqTCA6W+JbPryhy2YjVwdH+JwYQGy4GbXYxbKZp5ZXAf5/9/y6j8Bns
Hrxv5pvCOb08aArhQE6ht0NTqaIYsSf/7TeW1e+da5ikLbrcFUcXVzKWtZPcbz4Y
42G1AS9TLyyw01y6LUGK5WWy3ztD/8fyYVImG7q+8JGYKJpxI0fsLaEpDvHq5ZpO
PMJqT0tbaWwK8CtDcLEjv1bxmXUpD6c8FzffRwuy1SM6USMyAFFLdIVizjgekhRJ
POQTeO8NyR8O3ViT4Eq+ED051qk+oT99xvfHLOLk7BFMVYK3bYMmaOHlb9g060Og
32lFbcuDgGaGI2d+0cQrWemQiWjEMi55dIqXDmGiA3o18r7s0bEt7lPKFBqjrRfP
h9/+EqqpYkWjp623vOW+vHPgxUNcyGMXl/nZTcvhpJLOgBkjQnq7dSpV3LzrGNN3
mJFpKxQye7rccbZPa82ln5Y6+g97H/oy1FNkzNcI+Fv3BOCSQOoM9uPB6NP5b3se
JC8GW1ehLV/byfuwXSJJYo7csNiem90UTRR7ZDzjE8clbzATR0d+qJTf0idA5xDK
U+JwxqzW+ktBZwwS2t+A1QaHj7frJt0FuN1Us+bX6GcJ6X+JJsjxEp+WbKIncgQV
k6mcbVJmT6a4LyiFCN9oeDnkLM6L/wIDAQABAoICAHiLxmP+oplLXnWIR61r3vL4
fG7kSrFea1nohqLVgDz/oeI6aUTolzWMPWVVkI4sz+bxarDlhAPCtyaeZaMcLId8
SUYhlmYyNoq7tnE01Tg34Eo7aTfyM+kvSA7RBtcPc7J73VtD4GLp0I55bU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qDvR1pz
tvuarGIc32Of4/2OAIXzPH3IF5mWYYuvGA8vgmk1ZM/lcZ3DYhWuT7UiWQIS5GB+
NJYMf5xB9G5Wnmq5H9RmkeAozNjnSDZHGQiGLwKW4LVqbkSxGGbGpXS57Si+QvBJ
7sscXOjF3wtZdFCFacS9FPm9KRjD7AU=
-----END PRIVATE KEY-----
30 changes: 30 additions & 0 deletions cert/vault.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-----BEGIN CERTIFICATE-----
MIIFKzCCAxMCFDxrZQdK60TK6QxY01Y0QdRFrbdpMA0GCSqGSIb3DQEBCwUAMFIx
CzAJBgNVBAYTAlVTMQ8wDQYDVQQIDAZEZW5pYWwxFDASBgNVBAcMC1NwcmluZ2Zp
ZWxkMQwwCgYDVQQKDANEaXMxDjAMBgNVBAMMBXZhdWx0MB4XDTI0MTAxNTE4NTk1
N1oXDTI1MTAxNTE4NTk1N1owUjELMAkGA1UEBhMCVVMxDzANBgNVBAgMBkRlbmlh
bDEUMBIGA1UEBwwLU3ByaW5nZmllbGQxDDAKBgNVBAoMA0RpczEOMAwGA1UEAwwF
dmF1bHQwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC4GT1p/wZyxvMs
Z/N7g6HbSNqTCA6W+JbPryhy2YjVwdH+JwYQGy4GbXYxbKZp5ZXAf5/9/y6j8Bns
Hrxv5pvCOb08aArhQE6ht0NTqaIYsSf/7TeW1e+da5ikLbrcFUcXVzKWtZPcbz4Y
42G1AS9TLyyw01y6LUGK5WWy3ztD/8fyYVImG7q+8JGYKJpxI0fsLaEpDvHq5ZpO
PMJqT0tbaWwK8CtDcLEjv1bxmXUpD6c8FzffRwuy1SM6USMyAFFLdIVizjgekhRJ
POQTeO8NyR8O3ViT4Eq+ED051qk+oT99xvfHLOLk7BFMVYK3bYMmaOHlb9g060Og
32lFbcuDgGaGI2d+0cQrWemQiWjEMi55dIqXDmGiA3o18r7s0bEt7lPKFBqjrRfP
h9/+EqqpYkWjp623vOW+vHPgxUNcyGMXl/nZTcvhpJLOgBkjQnq7dSpV3LzrGNN3
mJFpKxQye7rccbZPa82ln5Y6+g97H/oy1FNkzNcI+Fv3BOCSQOoM9uPB6NP5b3se
JC8GW1ehLV/byfuwXSJJYo7csNiem90UTRR7ZDzjE8clbzATR0d+qJTf0idA5xDK
U+JwxqzW+ktBZwwS2t+A1QaHj7frJt0FuN1Us+bX6GcJ6X+JJsjxEp+WbKIncgQV
k6mcbVJmT6a4LyiFCN9oeDnkLM6L/wIDAQABMA0GCSqGSIb3DQEBCwUAA4ICAQBi
hcNthicAeN726BwOSt87q7T/MLJp543CtGcL8m0Z5N6ZlQhCdS3/aPKHXtksbtyY
3oXcMcXaROPkYDOn6F5bNmsLpkC6v/lZpN7yxFbNN2QZ9kqDquRoyIg9EQmOazIl
daahg7UoI3n2u/Rb5AJ0MmsfiKx2ybFTNwdI1Pg84Tp5k/VuvQ33bCxErIXjaaE0
60w7xUkus2WbrMTLgJOS+GdVIa+RmJVivK5c+ejJcE81bGEVuCnCxvPy7aIcwKy4
BGYxsVDW/9/rlm+z92KKcnvWFIxxlU+FTeXeOoIXAyRydOn9Eh7Is8Y6LoWf7U5S
n2uxMsjJ2kf08/2FcYjkPfgQm3PYKUS+xOBOE9ykT4t84v32c6sVvGMWMeHMJfMZ
CPF/Ok9CzvqWaMcVzLOeCQT4AAAT1yyNN0WaTMlx8UZthB/axR1uR5xcs/4VsVfq
K0ToIh9dmH4LLr5GB+RPLXLdoyS9JneMekkJHqq7PngcJztuhmq6EESVgdaEiQC4
HgMaWV9SLku7OxFa050qiCZGDvJU5emNkizWIkm91f3sXliLF9sl5BSnr/4UtlnA
ExU8iaglghbA0wfyGfXIUYtENGLh6b7PVOvT0eirSLgAvHijdCL0tiwssfl8a4W/
sYs2JyeEa3Dpf7qU6uHbg8TWEfZsulezprneVmgG4Q==
-----END CERTIFICATE-----
17 changes: 14 additions & 3 deletions config/astral.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
# Astral configuration
# Note that values can be supplied here or as environment vars (UPPER_CASE).
shared:
vault_addr:
vault_token:
vault_addr:
# if VAULT_ADDR is https with self-signed cert, need to provide
# CA cert (path to file)
Copy link
Collaborator

@GeorgeJahad GeorgeJahad Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment confused me for a bit. It would have been clearer to me if it read:

 # if VAULT_ADDR is https with self-signed cert, need to provide
 # CA cert (path to file) in "vault_ssl_cert" below:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated if you can please re-up the approval

vault_ssl_cert:
# Vault client cert if required (path to file)
vault_ssl_client_cert:
vault_ssl_client_key:

# Pre-existing root CA, or create new if requested
# Vault PKI configuration -- create root CA when true, or reference an existing
vault_create_root: true
vault_root_ca_ref: root_ca
vault_root_ca_mount: pki_root
cert_ttl:

jwt_signing_key:
cert_ttl:

# When using AppRegistry for Domain Ownership information
app_registry_addr:
app_registry_token:
app_registry_ca_file:
app_registry_client_cert:
app_registry_client_key:

# User activity logging
audit_log_file: <%= "#{Rails.root.join('log')}/astral-audit.log" %>

# Per-environment overrides of shared configs
test:
cert_ttl: <%= 24.hours.in_seconds %>

Expand Down
17 changes: 17 additions & 0 deletions lib/tasks/configure.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "rake"

# Rake tasks for making a vault cert
namespace :configure do
desc "Make the server cert for vault"
task :ssl do
%x(
openssl req -new -newkey rsa:4096 -nodes \
-keyout cert/vault.key -out cert/vault.csr \
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=vault"
openssl x509 -req -days 365 -in cert/vault.csr \
-signkey cert/vault.key \
-out cert/vault.pem
)
puts "SSL key for vault created"
end
end
4 changes: 2 additions & 2 deletions lib/tasks/redoc.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace :redoc do
task :bundle do
%x(
docker run -v /workspaces/astral/doc/openapi:/data -w /data \
redocly/cli bundle openapi.yml \
--output openapi-bundled.yml
redocly/cli bundle openapi.yml \
--output openapi-bundled.yml
)
puts "openapi.yml and references bundled to openapi-bundled.yml"
end
Expand Down