Skip to content
Open
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
6 changes: 6 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
- name: Convert PEM to JWK
run: |
gem install --user-install json-jwt
export TF_VAR_okta_jwk_n=`ruby scripts/jwk.rb`
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
Expand All @@ -33,6 +37,8 @@ jobs:
run: terraform fmt -check -diff
- name: Terraform Init
id: init
env:
TF_CLI_ARGS: ${{ secrets.TF_CLI_ARGS }}
run: terraform init
- name: Terraform Plan
id: plan
Expand Down
43 changes: 35 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,56 @@ terraform {
region = "us-west-2"
key = "indent/terraform.tfstate"
}
}

# Configure the Okta Provider
provider "okta" {
org_name = var.okta_prefix
base_url = "okta.com"
api_token = var.okta_token

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the Number 1 thing here: we need to handle this gracefully: what happens when we delete the token?

Current thought is a runonce stage that sets up the okta_app_oauth; we can then read the necessary values from state in the bucket without having to refresh it (and run into API rejections from token revocation).

}

# Indent + Okta Integration

# Details: https://github.com/indentapis/integrations/tree/f494cef86094c3b40ac124e3159f5f3391c7e6c8/packages/stable/indent-integration-okta
# Last Change: https://github.com/indentapis/integrations/commit/f494cef86094c3b40ac124e3159f5f3391c7e6c8
# Details: https://github.com/indentapis/integrations/tree/f0cea0e363f8950c7a217d186df6c377ed52e9d7/packages/stable/indent-integration-okta
# Last Change: https://github.com/indentapis/integrations/commit/f0cea0e363f8950c7a217d186df6c377ed52e9d7

module "idt-okta-webhook" {
source = "git::https://github.com/indentapis/integrations//terraform/modules/indent_runtime_aws_lambda"
name = "idt-okta-webhook"
indent_webhook_secret = var.indent_webhook_secret
artifact = {
bucket = "indent-artifacts-us-west-2"
function_key = "webhooks/aws/lambda/okta-f494cef86094c3b40ac124e3159f5f3391c7e6c8-function.zip"
deps_key = "webhooks/aws/lambda/okta-f494cef86094c3b40ac124e3159f5f3391c7e6c8-deps.zip"
function_key = "webhooks/aws/lambda/okta-f0cea0e363f8950c7a217d186df6c377ed52e9d7-function.zip"
deps_key = "webhooks/aws/lambda/okta-f0cea0e363f8950c7a217d186df6c377ed52e9d7-deps.zip"
}
env = {
OKTA_DOMAIN = var.okta_domain
OKTA_TOKEN = var.okta_token
OKTA_DOMAIN = "${var.okta_prefix}.okta.com"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this into a generated locals

# OKTA_TOKEN = var.okta_token
OKTA_SLACK_APP_ID = var.okta_slack_app_id
OKTA_CLIENT_ID = var.okta_client_id
OKTA_PRIVATE_KEY = var.okta_private_key
OKTA_CLIENT_ID = okta_app_oauth.indent.id
OKTA_PRIVATE_KEY = file("./private.pem")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is generated by the jwk.rb script, which also sets a TF_VAR for the jwk n value. Clean this up -- make them both vars, probably (and ignore changes as well).

}
}

resource "okta_app_oauth" "indent" {
label = "indent_integration"
type = "service"
token_endpoint_auth_method = "private_key_jwt"
grant_types = ["client_credentials"]
response_types = ["token"]
pkce_required = true

jwks {
kty = "RSA"
kid = "SIGNING_KEY"
e = "AQAB"
n = var.okta_jwk_n
}
}

resource "okta_app_oauth_api_scope" "indent-scopes" {
app_id = okta_app_oauth.indent.id
issuer = "https://${var.okta_prefix}.okta.com"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use generated local for this

scopes = ["okta.groups.manage", "okta.users.manage"]
}
6 changes: 6 additions & 0 deletions scripts/jwk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'openssl'
require 'json/jwt'
rsa_private = OpenSSL::PKey::RSA.generate 2048
File.write('./private.pem', rsa_private.to_pem)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either all file output, or all env var.

rsa_private = OpenSSL::PKey::RSA.new rsa_private_string
puts rsa_private.public_key.to_jwk["n"]
19 changes: 19 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ variable "okta_domain" {
default = ""
sensitive = true
}
variable "okta_prefix" {
type = string
default = ""
sensitive = true
}

variable "okta_private_key" {
type = string
default = ""
sensitive = true
}

variable "okta_jwk_n" {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did it this way because it was easier to get working, but should fully flesh this out as the full jwk, or even the full pub/priv key and read fields from it at a time.

# just the `n` portion of the okta jwk;
# TF_VARS_okta_private_key="" scripts/jwk.rb
type = string
default = ""
sensitive = true
}

variable "okta_token" {
type = string
Expand Down