Skip to content

Commit

Permalink
Merge branch 'main' of github.com:G-Research/astral
Browse files Browse the repository at this point in the history
  • Loading branch information
suprjinx committed Oct 22, 2024
2 parents 88b65d4 + b3f3ec2 commit d87c082
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ USER rails:rails
# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
# Start the server
CMD ["bin/rails", "server", "-b", "0.0.0.0"]
CMD ["bin/http.sh"]
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,37 @@ 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`:
Astral can be run as an SSL service and can communicate with Vault via SSL.
Just set the following values in `config/astral.yml` (or environment) to
encrypt Astral-to-Vault :
```
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:

A self-signed server cert for Vault, Astral, and the OIDC provider can be
generated with the following command, and initial placeholder certs are already provided.
```
rake configure:ssl
```

To use SSL in the devcontainer, edit `.devcontainer/docker-compose.yml` so
that the `app` service has `VAULT_ADDRESS` of `https://vault:8443`.
To use Vault SSL in the devcontainer, edit
`.devcontainer/docker-compose.yml` so that the `app` service has
`VAULT_ADDRESS` of `https://vault:8443`. Client certs can also be
configured -- in which case Vault needs to supplied with a CA for
peer verification.

To use Astral with SSL in production, provide the necessary
environment (ASTRAL_SSL_CERT, ASTRAL_SSL_KEY) to the container
environment, and use the `bin/ssl.sh` startup command. Eg:
```
docker run -p 3000:3000 \
-e ASTRAL_SSL_CERT=/certs/cert.pem \
-e ASTRAL_SSL_KEY=/certs/key.key \
-v certs:/certs:cached \
astral:latest bin/ssl.sh
```

## OIDC configuration
The OIDC modules allow the assignment of a policy to an OIDC user, by
Expand Down Expand Up @@ -123,6 +139,8 @@ config/astral.yml).
The rails test's configure the OIDC initial user, so if the tests pass,
you can invoke the oidc login as follows:

To use SSL in production, provide the necessary environment (SSL_CERT, SSL_KEY) to
the container environment, and use the `bin/ssl.sh` startup command. Eg:
```
export VAULT_ADDR=http://127.0.0.1:8200; vault login -method=oidc
```
Expand Down
2 changes: 2 additions & 0 deletions bin/http.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#! /bin/sh
bin/rails s -b 0.0.0.0
5 changes: 5 additions & 0 deletions bin/ssl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /bin/sh
ASTRAL_SSL_CERT="${SSL_CERT:-cert/astral.pem}"
ASTRAL_SSL_KEY="${SSL_KEY:-cert/astral.key}"

bin/rails s -b "ssl://0.0.0.0:3000?key=${ASTRAL_SSL_KEY}&cert=${ASTRAL_SSL_CERT}"
28 changes: 28 additions & 0 deletions cert/astral.csr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN CERTIFICATE REQUEST-----
MIIEvDCCAqQCAQAwUzELMAkGA1UEBhMCVVMxDzANBgNVBAgMBkRlbmlhbDEUMBIG
A1UEBwwLU3ByaW5nZmllbGQxDDAKBgNVBAoMA0RpczEPMA0GA1UEAwwGYXN0cmFs
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnikPRYuwiWfHxN2V8/NP
SEhztM9m76gMfKoFQMdDLLLIBSicFxNFRJogkcWGnkEGIWNCQeXpFuihl3CWXmdo
ubqhHpVjcoG5iGXBDaDCSaImkFCmHNuetTkuIoM+UWZRlM7lkic5T1Kxy5Fr1dDd
F0vLNJ5uEBcJ5eufs8YaodzWzAk7HbJ1Du0Y3lS3cnEcEDFOSut2nT/fJyGKi1eA
YGm/NnBrDP5zto3XCxjXiLxIoZxLXJj/9Fzjs2L4j/FeaxTgTa7qzmAtxZcxnm81
nO8jOzsEeCmLcp5oMJQPOJ+5GL4Lq4TDjBxc/IVhHpCRMWhvCv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W9w9TAdaZglkt6M1AXesh8F3F11lMtrIy7BFdcxTaPbPMui3zV3hNd7b64Vc
+qHZal53OFX+CAApKa4MSQ==
-----END CERTIFICATE REQUEST-----
52 changes: 52 additions & 0 deletions cert/astral.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQCeKQ9Fi7CJZ8fE
3ZXz809ISHO0z2bvqAx8qgVAx0MsssgFKJwXE0VEmiCRxYaeQQYhY0JB5ekW6KGX
cJZeZ2i5uqEelWNygbmIZcENoMJJoiaQUKYc2561OS4igz5RZlGUzuWSJzlPUrHL
kWvV0N0XS8s0nm4QFwnl65+zxhqh3NbMCTsdsnUO7RjeVLdycRwQMU5K63adP98n
IYqLV4Bgab82cGsM/nO2jdcLGNeIvEihnEtcmP/0XOOzYviP8V5rFOBNrurOYC3F
lzGebzWc7yM7OwR4KYtynmgwlA84n7kYvgurhMOMHFz8hWEekJExaG8K+gM8GpCA
DVMVWnF5G+VTg3hydxuTtfsDNQlZleEVYZuMlGpGXNOXsaOzt9O+aNAQw3FlUPkX
vb8B4mhaK3QyAFnmxuyxs21LwXhau6MjRk9YzYqE0JV1SNL0T1RQ674Iivt2B2Jk
N7/atu82Nv4aluPyIE/Xyiw6gJ8CwSfJCk4N+w7lzkhf+5sRbOx1ARMTXt4Xm6T/
5kxCP7Z/rbmmaf67MM+MQctPEogse4lw/JLJ5GS077mooucqpSrlVoERox8nyMqN
sgM8A/BUsGnY1TNmBkF5ebA68u0AVZEFehtfyFbcpGqVnQUAwO4NGuy6v0llMw61
5KubtK/XC8RDldhq/de6W3EWp4fleQIDAQABAoICAF1W1AlyECR3V+Ep+HY5EIAT
Kh36DMDBB2WHHYSGVHGLrRnGRqAjokyDPVdqIDFDJLANmSu02KPJdJwgOM3L73U0
3CNlfIQ2ZN1HV/CIAEFeba3burzrK7W94ilCFUQKw3izxa5EccELh5wg3Wg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Iin5I6QU2I//mytAkaBKyoPCrTxxw3TFlkRvNHK9IIs9BMDwUmFM+JgF
2A9/ooRdAYT8rLmoR6t2QFtHgqWBgKvhnKnqNV1oeVp8OYZoGS3EEw2foJOt37fo
2HQc6yP5r2gYlP78sFptd09YRT8oCA==
-----END PRIVATE KEY-----
31 changes: 31 additions & 0 deletions cert/astral.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----BEGIN CERTIFICATE-----
MIIFSTCCAzGgAwIBAgIUIOIfpkyG8YDizn/N7dOZl1etxpgwDQYJKoZIhvcNAQEL
BQAwUzELMAkGA1UEBhMCVVMxDzANBgNVBAgMBkRlbmlhbDEUMBIGA1UEBwwLU3By
aW5nZmllbGQxDDAKBgNVBAoMA0RpczEPMA0GA1UEAwwGYXN0cmFsMB4XDTI0MTAy
MjE4MzExNFoXDTI1MTAyMjE4MzExNFowUzELMAkGA1UEBhMCVVMxDzANBgNVBAgM
BkRlbmlhbDEUMBIGA1UEBwwLU3ByaW5nZmllbGQxDDAKBgNVBAoMA0RpczEPMA0G
A1UEAwwGYXN0cmFsMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnikP
RYuwiWfHxN2V8/NPSEhztM9m76gMfKoFQMdDLLLIBSicFxNFRJogkcWGnkEGIWNC
QeXpFuihl3CWXmdoubqhHpVjcoG5iGXBDaDCSaImkFCmHNuetTkuIoM+UWZRlM7l
kic5T1Kxy5Fr1dDdF0vLNJ5uEBcJ5eufs8YaodzWzAk7HbJ1Du0Y3lS3cnEcEDFO
Sut2nT/fJyGKi1eAYGm/NnBrDP5zto3XCxjXiLxIoZxLXJj/9Fzjs2L4j/FeaxTg
Ta7qzmAtxZcxnm81nO8jOzsEeCmLcp5oMJQPOJ+5GL4Lq4TDjBxc/IVhHpCRMWhv
CvoDPBqQgA1TFVpxeRvlU4N4cncbk7X7AzUJWZXhFWGbjJRqRlzTl7Gjs7fTvmjQ
EMNxZVD5F72/AeJoWit0MgBZ5sbss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 deletions lib/tasks/configure.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,40 @@ require "rake"

# Rake tasks for making a vault cert
namespace :configure do
desc "Make Vault, Astral, and OIDC provider certs"
task ssl: [ :vault_ssl, :astral_ssl, :oidc_provider_ssl ]

desc "Make the server cert for vault"
task :ssl, [ :cert_name ] do |t, args|
cert_name = args[:cert_name]
cert_name = "vault" if cert_name.nil?
sanParam = "subjectAltName=DNS:#{cert_name}"
%x(
openssl req -new -newkey rsa:4096 -nodes \
-keyout cert/#{cert_name}.key -out cert/#{cert_name}.csr \
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=#{cert_name}" \
-addext #{sanParam} \
task :vault_ssl do
keygen("vault")
end

desc "Make the server cert for astral"
task :astral_ssl do
keygen("astral")
end

echo #{sanParam} > /tmp/sanParam
openssl x509 -req -days 365 -in cert/#{cert_name}.csr \
-signkey cert/#{cert_name}.key \
-out cert/#{cert_name}.pem -extfile /tmp/sanParam
desc "Make the server cert for the oidc provider"
task :oidc_provider_ssl do
keygen("oidc_provider")
end

private

def keygen(name)
san_param_file = "/tmp/san_param_#{name}"
san_param_content = "subjectAltName=DNS:#{name}"
File.write(san_param_file, san_param_content)
%x(
openssl req -new -newkey rsa:4096 -nodes \
-keyout cert/#{name}.key -out cert/#{name}.csr \
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=#{name}" \
-addext #{san_param_content}
openssl x509 -req -days 365 -in cert/#{name}.csr \
-signkey cert/#{name}.key \
-out cert/#{name}.pem \
-extfile #{san_param_file}
)
puts "SSL key for #{cert_name} created"
puts "SSL key for #{name} created"
end
end

0 comments on commit d87c082

Please sign in to comment.