Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
21a7f22
Add Authlib package dependency
jonathansick Oct 7, 2021
e3eca8b
Add credential configs for GitHub OAuth client
jonathansick Oct 7, 2021
4d69bf8
Add itsdangeorus for sessions middleware
jonathansick Oct 7, 2021
d0d648b
Fix env var name for S3 prefix config
jonathansick Oct 7, 2021
acd3424
Add configuration for session key
jonathansick Oct 7, 2021
4fef6b4
Add sessions middleware
jonathansick Oct 7, 2021
21b021a
Improve S3 bucket dependency naming
jonathansick Oct 12, 2021
b23cb37
Demonstrate GitHub OAuth
jonathansick Oct 12, 2021
bc612a3
Add gidgethub dependency
jonathansick Oct 25, 2021
6a067ad
Add GitHub org and team memberships to session
jonathansick Oct 25, 2021
2818ccb
Add pyyaml dependency
jonathansick Nov 2, 2021
17edd1c
Configure path to file with GitHub auth rules
jonathansick Nov 3, 2021
d4de567
Add GitHubAuth
jonathansick Nov 3, 2021
f8bad48
Implement GitHub auth on the proxy handler
jonathansick Nov 3, 2021
e96a1a4
Drop tests for internal handlers
jonathansick Nov 3, 2021
935bec0
Add path_prefix configuration to serve from root
jonathansick Nov 3, 2021
2d4faad
Compute redirect URLs using request.url_for
jonathansick Nov 3, 2021
bbe8b33
Add configuration for the GitHub OAuth callback
jonathansick Nov 3, 2021
b9cdb58
Redirect users to the original page after login
jonathansick Nov 4, 2021
02b8234
Remove default homepage
jonathansick Nov 4, 2021
20530d3
Implement implicit index.html rewrites on S3
jonathansick Nov 4, 2021
ffe2597
Handle 404 status from S3
jonathansick Nov 4, 2021
543cbb9
Shift logging to debug level
jonathansick Nov 4, 2021
a373867
Disable OpenAPI docs
jonathansick Nov 4, 2021
6695cdf
Add a health check endpoint for Kubernetes
jonathansick Nov 4, 2021
4945071
Add additional configurations manifests
jonathansick Nov 4, 2021
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
26 changes: 25 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,28 @@
ltd-proxy
#########

LTD Proxy is a secure front-end proxy for LTD projects.
LTD Proxy is a secure front-end proxy for LTD projects that are hosted on Amazon AWS.
It uses GitHub OAuth to authenticate visitors and GitHub organization and/or team memberships to authorize access to pages at specific URL path prefixes.

Kubernetes deployment
=====================

Secret resource
---------------

Besides the ConfigMaps, your kustomized deployment needs to include a secret resource that is referenced as environment variables from the deployment's ``app`` container.
This secret could be generated from a Vault secret or an AWS Secret, or could be a plain Kubernetes Secret, such as:

.. code-block:: yaml

apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: ltdproxy
data:
LTDPROXY_AWS_ACCESS_KEY_ID: ...
LTDPROXY_AWS_SECRET_ACCESS_KEY: ...
LTDPROXY_GITHUB_OAUTH_ID: ...
LTDPROXY_GITHUB_OAUTH_SECRET: ...
LTDPROXY_SESSION_KEY: ...
16 changes: 16 additions & 0 deletions manifests/base/auth-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: "ltdproxy-auth"
labels:
app.kubernetes.io/name: "ltd-proxy"
data:
authrules.yaml: |
default:
- org: "jsickcodes"
paths: []
- pattern: "\/a\/"
authorized:
- org: "jsickcodes"
team: "Red Team"

4 changes: 4 additions & 0 deletions manifests/base/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ data:
SAFIR_LOGGER: "ltdproxy"
SAFIR_LOG_LEVEL: "INFO"
SAFIR_PROFILE: "production"
LTDPROXY_AUTH_CONFIG: "/opt/ltdproxy/auth/authrules.yaml"
LTDPROXY_PATH_PREFIX: "/"
LTDPROXY_S3_BUCKET: ""
LTDPROXY_S3_PREFIX: ""
LTDPROXY_AWS_REGION: ""
LTDPROXY_GITHUB_CALLBACK_URL: ""
10 changes: 9 additions & 1 deletion manifests/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
- name: app
imagePullPolicy: "IfNotPresent"
# Use images field in a Kustomization to set/update image tag
image: "lsstsqre/ltdproxy"
image: "ghcr.io/jsickcodes/ltd-proxy"
ports:
- containerPort: 8080
name: "app"
Expand All @@ -32,6 +32,14 @@ spec:
drop:
- "all"
readOnlyRootFilesystem: true
volumeMounts:
- name: "auth-config"
mountPath: "/opt/ltdproxy/auth/"
readOnly: true
volumes:
- name: "auth-config"
configMap:
name: "ltdproxy-auth"
securityContext:
runAsNonRoot: true
runAsUser: 1000
Expand Down
1 change: 1 addition & 0 deletions manifests/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ images:

resources:
- configmap.yaml
- auth-configmap.yaml
- deployment.yaml
- service.yaml
1 change: 1 addition & 0 deletions requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ pytest
pytest-asyncio
pytest-cov
uvicorn
types-PyYAML
258 changes: 131 additions & 127 deletions requirements/dev.txt

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions requirements/main.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ fastapi
gunicorn
starlette
uvicorn[standard]
PyYAML

# Other dependencies.
safir
httpx
aws-request-signer
python-dotenv
Authlib
itsdangerous
gidgethub
238 changes: 173 additions & 65 deletions requirements/main.txt

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src/ltdproxy/appsetup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Configuration for the app."""

from __future__ import annotations

from importlib.metadata import metadata
from typing import TYPE_CHECKING

from .handlers.external import external_router
from .handlers.healthcheck import health_router
from .handlers.internal import internal_router

if TYPE_CHECKING:
from fastapi import FastAPI

from ltdproxy.config import Configuration


def add_handlers(*, config: Configuration, app: FastAPI) -> None:
if config.path_prefix == "/":
app.include_router(health_router)
app.include_router(external_router)
else:
external_app = FastAPI(
title="ltd-proxy",
description=metadata("ltd-proxy").get("Summary", ""),
version=metadata("ltd-proxy").get("Version", "0.0.0"),
openapi_url=None,
)
external_app.include_router(external_router)

app.include_router(internal_router)
app.include_router(health_router)
app.mount(f"{config.path_prefix}", external_app)
20 changes: 18 additions & 2 deletions src/ltdproxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
from enum import Enum

from pydantic import BaseSettings, Field, SecretStr
from pydantic import BaseSettings, Field, FilePath, HttpUrl, SecretStr

__all__ = ["Configuration", "config", "Profile", "LogLevel"]

Expand Down Expand Up @@ -43,7 +43,7 @@ class Configuration(BaseSettings):

s3_bucket: str = Field("test", env="LTDPROXY_S3_BUCKET")

s3_bucket_prefix: str = Field("", env="LTD_PROXY_S3_PREFIX")
s3_bucket_prefix: str = Field("", env="LTDPROXY_S3_PREFIX")

aws_region: str = Field("us-central-1", env="LTDPROXY_AWS_REGION")

Expand All @@ -53,6 +53,22 @@ class Configuration(BaseSettings):
..., env="LTDPROXY_AWS_SECRET_ACCESS_KEY"
)

github_oauth_client_id: str = Field(env="LTDPROXY_GITHUB_OAUTH_ID")

github_oauth_client_secret: SecretStr = Field(
env="LTDPROXY_GITHUB_OAUTH_SECRET"
)

github_oauth_callback_url: HttpUrl = Field(
env="LTDPROXY_GITHUB_CALLBACK_URL"
)

session_key: SecretStr = Field(env="LTDPROXY_SESSION_KEY")

github_auth_config_path: FilePath = Field(env="LTDPROXY_AUTH_CONFIG")

path_prefix: str = Field("/", env="LTDPROXY_PATH_PREFIX")


config = Configuration(_env_file=os.getenv("LTD_PROXY_ENV"))
"""Configuration for ltd-proxy."""
Loading