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

Updated storage api to enforce JWT #22

Merged
merged 1 commit into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions terraform/ocwa_storage_api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ resource "docker_container" "minio" {
]
}

data "local_file" "pre_create_py" {
filename = "${path.module}/scripts/pre-create.py"
}

resource "local_file" "pre_create" {
content = "${data.local_file.pre_create_py.content}"
filename = "${var.hostRootPath}/config/tusd/pre-create"
}

data "docker_registry_image" "tusd" {
name = "tusproject/tusd${var.images["tusd"]}"
name = "h3brandon/tusd_py3${var.images["tusd"]}"
}

resource "docker_image" "tusd" {
Expand All @@ -40,13 +48,19 @@ resource "docker_image" "tusd" {
resource "docker_container" "tusd" {
image = "${docker_image.tusd.latest}"
name = "ocwa_tusd"
volumes = {
host_path = "${var.hostRootPath}/config/tusd"
container_path = "/srv/tusd-hooks"
}
restart = "on-failure"
command = [ "-behind-proxy", "-s3-bucket", "bucket", "-s3-endpoint", "http://ocwaminio:9000" ]
command = [ "--hooks-dir", "/srv/tusd-hooks", "-behind-proxy", "-s3-bucket", "bucket", "-s3-endpoint", "http://ocwaminio:9000" ]
networks_advanced = { name = "${docker_network.private_network.name}" }
env = [
"AWS_ACCESS_KEY=${random_id.accessKey.hex}",
"AWS_SECRET_ACCESS_KEY=${random_string.secretKey.result}",
"AWS_REGION=not_applicable"
"AWS_REGION=not_applicable",
"JWT_SECRET=${random_string.jwtSecret.result}",
"JWT_AUD=outputchecker"
]
}

Expand Down
30 changes: 30 additions & 0 deletions terraform/scripts/pre-create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python3
import fileinput
import json
import os
import jwt

jsonStr = ""

for line in fileinput.input():
jsonStr += line

js = json.loads(jsonStr)

if 'MetaData' in js:
meta = js['MetaData']
if 'jwt' in meta:
tok = meta['jwt']
jwtSecret = os.environ['JWT_SECRET']
aud = os.environ['JWT_AUD']
try:
jwt.decode(tok, jwtSecret, audience=aud)
#Valid JWT
exit(0)
except Exception as e:
print(e)


print ('Either no JWT Or invalid JWT given')
#Forbidden because jwt not specified or invalid
exit(403)