-
Notifications
You must be signed in to change notification settings - Fork 1
feat(oidc): add oidc support #50
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
Conversation
|
LGTM, move OIDC to separate module under |
variables.tf
Outdated
| } | ||
|
|
||
| variable "oidc" { | ||
| description = "Seznam OIDC providerů" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List
| const [value, signature] = session.split('.'); | ||
| console.log('Edge Lambda - Session cookie parts - Value:', value, 'Signature:', signature); | ||
|
|
||
| // Pokud je providerKey přítomen, validujeme jen pro konkrétního providera |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English comments
| // Pokud máme session cookie, zkusíme ji validovat | ||
| if (session) { | ||
| console.log('Edge Lambda - Found session cookie:', session); | ||
| // Kontrola formátu session cookie (měla by být ve formátu value.signature) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English comments
| console.log('Edge Lambda - No cookie header present or not an array'); | ||
| } | ||
|
|
||
| // Pokud máme session cookie, zkusíme ji validovat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English comments
\# Example
1. Create OIDC app
just for the reference, gitlab_application is server wide and not ideal for use e.g. on gitlab.com, there's no support for the group applications
```tf
resource "gitlab_application" "fridges_list" {
name = "gitlab-app"
redirect_url = "www.example.com"
scopes = [
"openid",
"read_user",
"profile",
"email",
]
}
```
2. use module
```tf
module "static_site" {
source = "cookielab/static-site/aws"
version = "4.9.0"
providers = {
aws = aws
aws.us_east_1 = aws.vir
}
domains = ["www.exmaple.com"]
domain_zone_id = "aws_route53_zone.example_com.zone_id"
s3_bucket_name = "example-com-web"
gitlab_project_id = data.gitlab_project.app_fridges_list.id
gitlab_environment = var.environment
enable_deploy_role = true
enable_deploy_user = false
oidc = [
{ # first oidc provider
application_name = "gitlab"
application_id = gitlab_application.gitlab_application.application_id
client_secret = gitlab_application.gitlab_application.secret
auth_url = "https://gitlab.com/oauth/authorize"
token_url = "https://gitlab.com/oauth/token"
},
{ # second oidc provider
application_name = "second"
application_id = "second-oidc-app-id"
client_secret = "second-oidc-client-secret"
auth_url = "https://another-oidc-provicer.example.com/oauth/authorize"
token_url = "https://another-oidc-provicer.example.com/oauth/token"
}
]
```
Then https://www.example.com/?auth=APPLICATION_NAME forces auth with specified provider, e.g.:
- https://www.example.com/?auth=gitlab
- https://www.example.com/?auth=second
This is messy. Perhaps we can get along with a single OIDC auth for the application or if no session cookie is present redirect to a url hosted on s3 bucket with constructed html from the oidc list.
```
<h1>Choose authentication method</h1>
<ul>
<li>
<a href=/?auth=gitlab>gitlab</a>
</li>
<li>
<a href=/?auth=second>gitlab</a>
</li>
</ul>
```
fmt
cleanup
review: update lambda engine version nodejs18.x -> nodejs22.x
replace apigateway with lambda_function_url
update docs + fix duplicate blocks of outdated documentation due to missing BEGIN_TF_DOCS comment
review
parametrize session_duration per provider, fix cookie domain
comment sensitive log messages in lambdas
Notes
The OIDC applications need to be setup in advance
the oidc applications are configured via module's
oidcvariable - list of objects. Multiple oidc applications can be provided, you can select which provider to authenticate by appending ?auth=PROVIDER_NAME to urlchanges to the original main module:
new resources:
aws_cloudfront_cache_policy.oidcaws_cloudfront_origin_request_policy.oidcchanged blocks:
custom_error_responseinaws_cloudfront_distribution.thisis now conditionaly removed if oidc is enabled, to prevent serving content on errordefault_cache_behaviorinaws_cloudfront_distribution.thisconditionally enables forwarding all cookies if oidc is enabledadded blocks:
originfor api gateway inaws_cloudfront_distribution.this- dynamically created if oidc is enabledlambda_function_associationinaws_cloudfront_distribution.thisdynamically created if oidc is enabled for edge lambda handling redirects to oidc providerordered_cache_behaviorinaws_cloudfront_distribution.this- dynamically created if oidc is enabled, configuring /callback route to point to api gateway origin handling with callbacksExample
Then https://www.example.com/?auth=APPLICATION_NAME forces auth with specified provider, e.g.:
This is messy. Perhaps we can get along with a single OIDC auth for the application. Or constructed html file from the oidc list, put it on S3 and redirect if no session cookie is present: