-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from CanDIG/daisieh/vault-opa
DIG-1169, DIG-1402: Opa uses Vault for secret storage
- Loading branch information
Showing
9 changed files
with
122 additions
and
45 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 |
---|---|---|
@@ -1,32 +1,33 @@ | ||
ARG venv_python | ||
ARG alpine_version | ||
FROM python:${venv_python}-alpine${alpine_version} | ||
FROM python:${venv_python} | ||
|
||
LABEL Maintainer="CanDIG Project" | ||
LABEL "candigv2"="opa" | ||
|
||
USER root | ||
|
||
RUN addgroup -S candig && adduser -S candig -G candig | ||
RUN groupadd -r candig && useradd -rm candig -g candig | ||
|
||
RUN apk update | ||
|
||
RUN apk add --no-cache \ | ||
RUN apt-get update && apt-get -y install \ | ||
bash \ | ||
expect \ | ||
jq \ | ||
curl | ||
curl \ | ||
vim \ | ||
git | ||
|
||
COPY ./ /app/ | ||
COPY requirements.txt /app/requirements.txt | ||
|
||
RUN pip install --no-cache-dir -r /app/requirements.txt | ||
|
||
WORKDIR /app/ | ||
COPY ./ /app/ | ||
|
||
RUN chown -R candig:candig /app | ||
|
||
USER candig | ||
|
||
WORKDIR /app/ | ||
|
||
RUN touch /app/initial_setup | ||
|
||
ENTRYPOINT ["bash", "/app/entrypoint.sh"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import json | ||
import os | ||
from authx.auth import get_vault_token_for_service | ||
import sys | ||
import requests | ||
|
||
|
||
# get the token for the opa store | ||
try: | ||
with open("/run/secrets/opa-root-token") as f: | ||
OPA_ROOT_TOKEN = f.read().strip() | ||
opa_token = get_vault_token_for_service("opa") | ||
headers = { | ||
"X-Opa": OPA_ROOT_TOKEN, | ||
"Content-Type": "application/json; charset=utf-8" | ||
} | ||
payload = f"{{\"token\": \"{opa_token}\"}}" | ||
response = requests.put(url=f"{os.getenv('OPA_URL')}/v1/data/store_token", headers=headers, data=payload) | ||
print(response.text) | ||
except Exception as e: | ||
print(str(e)) | ||
sys.exit(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,39 @@ | ||
import json | ||
import os | ||
from authx.auth import set_service_store_secret, add_provider_to_opa | ||
import sys | ||
|
||
## Initializes Vault's opa service store with the information for our IDP and the data in access.json and paths.json | ||
|
||
results = [] | ||
|
||
try: | ||
with open('/app/bearer.txt') as f: | ||
try: | ||
token = f.read().strip() | ||
response, status_code = set_service_store_secret("opa", key="data", value=json.dumps({"keys":[]})) | ||
response = add_provider_to_opa(token, os.getenv("KEYCLOAK_REALM_URL")) | ||
results.append(response) | ||
except Exception as e: | ||
print(str(e)) | ||
sys.exit(1) | ||
|
||
with open('/app/permissions_engine/access.json') as f: | ||
data = f.read() | ||
response, status_code = set_service_store_secret("opa", key="access", value=data) | ||
if status_code != 200: | ||
sys.exit(2) | ||
results.append(response) | ||
|
||
with open('/app/permissions_engine/paths.json') as f: | ||
data = f.read() | ||
response, status_code = set_service_store_secret("opa", key="paths", value=data) | ||
if status_code != 200: | ||
sys.exit(3) | ||
results.append(response) | ||
except Exception as e: | ||
print(str(e)) | ||
sys.exit(4) | ||
|
||
# print(json.dumps(results, indent=4)) | ||
sys.exit(0) |
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
requests | ||
requests | ||
jq | ||
candigv2-authx@git+https://github.com/CanDIG/[email protected] |