Skip to content

Standards #1

Merged
merged 57 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f02bd6d
add pre-commit and db pre-reqs
morga471 Feb 25, 2025
a953914
split out main.tf
morga471 Feb 26, 2025
99ec049
validate passes
morga471 Feb 26, 2025
c4c058c
turn off db
morga471 Feb 26, 2025
615f9f9
remove db vars
morga471 Feb 26, 2025
d1c27fc
remove db related outputs
morga471 Feb 26, 2025
40c6009
remove not comment
morga471 Feb 26, 2025
826d42e
update keycloak key
morga471 Feb 26, 2025
8da6735
use main
morga471 Feb 26, 2025
a2bba53
unsupported
morga471 Feb 26, 2025
36c612a
to match config
morga471 Feb 26, 2025
e10cdc2
use existing feature branch
morga471 Feb 26, 2025
981fdaf
simplify
morga471 Feb 27, 2025
de6aa68
keycloak/keycloak
morga471 Feb 27, 2025
ea373e2
use quay.io due to rate limits
morga471 Feb 27, 2025
9b71da6
wait till service is created to create ingress
morga471 Feb 27, 2025
b57b5be
deps
morga471 Feb 27, 2025
8204c64
add missing tag vars
morga471 Feb 27, 2025
31794e1
pull from aws
morga471 Feb 27, 2025
48e3d48
more config
morga471 Feb 27, 2025
3e47c39
more config
morga471 Feb 27, 2025
6b3930e
prefix
morga471 Feb 27, 2025
4eca584
these too
morga471 Feb 27, 2025
bcaa9bc
inseucrity
morga471 Feb 27, 2025
3394450
add service_name
morga471 Feb 28, 2025
c38da40
service dns name
morga471 Feb 28, 2025
4e9a0bc
add postgres conf
morga471 Feb 28, 2025
788754c
fmt
morga471 Feb 28, 2025
c6d1d20
use embedded
morga471 Mar 3, 2025
27b08fd
comment unused
morga471 Mar 3, 2025
351978f
drop unused
morga471 Mar 3, 2025
b161553
remove unused
morga471 Mar 3, 2025
7beae2d
use downloaded chart
morga471 Mar 3, 2025
b81a14f
fix admin password
morga471 Mar 3, 2025
ed3e760
add postgres image
morga471 Mar 3, 2025
18a943b
add postgresql tag var
morga471 Mar 3, 2025
7e641cb
try to pull postgresql image
morga471 Mar 3, 2025
4f50d19
pass through postgesql chart vars
morga471 Mar 3, 2025
43d7f04
pass in existing secret
morga471 Mar 3, 2025
59c2998
name the password key password
morga471 Mar 3, 2025
51175b8
more passwords
morga471 Mar 3, 2025
a37b69b
move postgres-passowrd to keycloak-user-creds
morga471 Mar 3, 2025
79ee5e4
short timeout
morga471 Mar 3, 2025
4ef93d7
typo
morga471 Mar 3, 2025
e298426
enable serviceMonitor
morga471 Mar 3, 2025
ed7d755
use bitnami image for gatekeeper
morga471 Mar 4, 2025
d27837f
no gatekeeper
morga471 Mar 4, 2025
0916b3b
fix pdb
morga471 Mar 4, 2025
d73a110
fewer resources
morga471 Mar 7, 2025
7a616d2
not yet
morga471 Mar 7, 2025
bf38ec1
a little bigger
morga471 Mar 7, 2025
c30de6a
fewer configs
morga471 Mar 7, 2025
787d37d
let chart manage creds
morga471 Mar 7, 2025
a89ce74
cleanup
morga471 Mar 7, 2025
334a392
less is more
morga471 Mar 11, 2025
fbf13c1
password handling
morga471 Mar 11, 2025
1d8c2ed
enable namespace create
morga471 Mar 11, 2025
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
10 changes: 10 additions & 0 deletions .cz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
commitizen:
name: cz_conventional_commits
tag_format: v$version
version: 0.1.0
version_files:
- version.tf:module_version
bump_message: "bump: version $current_version → $new_version"
changelog_incremental: true
update_changelog_on_bump: true
104 changes: 104 additions & 0 deletions .github/workflows/terraform-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: 'Terraform Module CI'

on:
push:
branches:
- main
paths:
- '**/*.tf'
pull_request:
branches:
- main
paths:
- '**/*.tf'
workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
validate:
name: 'Validate Module'
runs-on: self-hosted

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.5.0

- name: Terraform Init
run: |
terraform init -backend=false
- name: Terraform Format
run: |
terraform fmt -check
- name: Terraform Validate
run: |
terraform validate
- name: Run tflint
uses: terraform-linters/setup-tflint@v3
if: github.event_name == 'pull_request'

- name: Lint Terraform
if: github.event_name == 'pull_request'
run: |
tflint --format compact
- name: Run Checkov
uses: bridgecrewio/checkov-action@master
with:
directory: .
framework: terraform
skip_check: CKV_AWS_115,CKV_AWS_116
quiet: true
soft_fail: true
output_format: sarif
output_file: checkov-results.sarif

release:
name: 'Create Release'
needs: validate
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: self-hosted
permissions:
contents: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install Commitizen
run: |
pip install commitizen
- name: Bump Version and Generate Changelog
id: cz
run: |
cz bump --yes
echo "new_version=$(cz version --project)" >> $GITHUB_OUTPUT
echo "changelog=$(cz changelog --dry-run)" >> $GITHUB_OUTPUT
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.cz.outputs.new_version }}
release_name: Release v${{ steps.cz.outputs.new_version }}
draft: false
prerelease: false
body: ${{ steps.cz.outputs.changelog }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc

109 changes: 109 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
# Git style
- id: check-added-large-files
- id: check-merge-conflict
- id: forbid-new-submodules
- id: no-commit-to-branch
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-json
- id: check-symlinks
# - id: check-vcs-permalinks
- id: check-toml
- id: check-xml
# - id: detect-private-key
- id: requirements-txt-fixer
- id: sort-simple-yaml

# Common errors
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
exclude: CHANGELOG.md
# - id: check-yaml
- id: check-merge-conflict
- id: check-executables-have-shebangs

# Cross platform
- id: check-case-conflict
- id: mixed-line-ending
args: [--fix=lf]

# Security
- id: detect-aws-credentials
args: ['--allow-missing-credentials']
# - id: detect-private-key

# JSON5 Linter
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
# https://prettier.io/docs/en/options.html#parser
files: '.json5$'

# Terraform Hooks
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.97.3 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
hooks:
- id: terraform_fmt
args:
- --hook-config=--parallelism-ci-cpu-cores=2
- id: terraform_docs
args:
- --hook-config=--parallelism-ci-cpu-cores=2
- id: terraform_tflint
name: Terraform validate with tflint
description: Validates all Terraform configuration files with TFLint.
require_serial: true
entry: hooks/terraform_tflint.sh
language: script
files: (\.tf|\.tfvars)$
exclude: \.(terraform/.*|terragrunt-cache)$
args:
- --hook-config=--parallelism-ci-cpu-cores=2
- id: terragrunt_fmt
name: Terragrunt fmt
description: Rewrites all Terragrunt configuration files to a canonical format.
entry: hooks/terragrunt_fmt.sh
language: script
files: (\.hcl)$
exclude: \.(terraform/.*|terragrunt-cache)$
args:
- --hook-config=--parallelism-ci-cpu-cores=2
# Will require dependency mocks
# - id: terragrunt_validate
# name: Terragrunt validate
# description: Validates all Terragrunt configuration files.
# entry: hooks/terragrunt_validate.sh
# language: script
# files: (\.hcl)$
# exclude: \.(terraform/.*|terragrunt-cache)$
# args:
# - --hook-config=--parallelism-ci-cpu-cores=2
# - id: terragrunt_validate_inputs
# name: Terragrunt validate inputs
# description: Validates Terragrunt unused and undefined inputs.
# entry: hooks/terragrunt_validate_inputs.sh
# language: script
# files: (\.hcl)$
# exclude: \.(terraform/.*|terragrunt-cache)$
# args:
# - --hook-config=--parallelism-ci-cpu-cores=2
# - id: terragrunt_providers_lock
# name: Terragrunt providers lock
# description: Updates provider signatures in dependency lock files using terragrunt.
# entry: hooks/terragrunt_providers_lock.sh
# language: script
# files: (terragrunt|\.terraform\.lock)\.hcl$
# exclude: \.(terraform/.*|terragrunt-cache)$
# args:
# - --hook-config=--parallelism-ci-cpu-cores=2

- repo: https://github.com/ljnsn/cz-conventional-gitmoji
rev: v0.6.1
hooks:
- id: conventional-gitmoji
112 changes: 112 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,113 @@
# tfmod-keycloak

Terraform module for deploying and configuring Keycloak on EKS clusters.

## Overview
- Deploys Keycloak identity and access management solution
- Configures AWS integration for authentication
- Sets up default realms and clients
- Manages pod security and networking policies

## Prerequisites
- Kubernetes cluster (EKS)
- Helm v3+
- AWS credentials with required permissions
- IAM roles and policies configured

## Usage

Basic example:
```hcl
module "keycloak" {
source = "git@github.e.it.census.gov:terraform-modules/tfmod-keycloak.git"
cluster_name = "my-eks-cluster"
keycloak_version = "21.1.1"
gogatekeeper_version = "3.7.4"
}
```

## Architecture
The module deploys the following components:
- Keycloak server pods with high availability
- PostgreSQL database for persistence
- GoGatekeeper for authentication proxy
- Required network policies and security groups

### Network Flow
1. External traffic -> ALB/NLB
2. ALB/NLB -> Keycloak Service
3. Keycloak -> PostgreSQL
4. GoGatekeeper -> Keycloak for auth

## Operations

### Monitoring
The module exposes the following metrics endpoints:
- Keycloak metrics: `/metrics`
- GoGatekeeper metrics: `/oauth/metrics`

### Troubleshooting
Common issues and solutions:
1. Database connectivity issues - Check security groups
2. Authentication failures - Verify realm configuration
3. Performance problems - Check resource requests/limits


<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 5.14 |
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | ~> 2.11 |
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | ~> 2.23 |
| <a name="requirement_null"></a> [null](#requirement\_null) | ~> 3.2 |
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.6 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_helm"></a> [helm](#provider\_helm) | 2.17.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_images"></a> [images](#module\_images) | git@github.e.it.census.gov:terraform-modules/aws-ecr-copy-images.git/ | tf-upgrade |
| <a name="module_ingress_resources"></a> [ingress\_resources](#module\_ingress\_resources) | git@github.e.it.census.gov:SCT-Engineering/tfmod-istio-service-ingress.git | main |

## Resources

| Name | Type |
|------|------|
| [helm_release.keycloak](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_cluster_domain"></a> [cluster\_domain](#input\_cluster\_domain) | The domain name used to reference ingresses for the cluster. | `string` | n/a | yes |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | EKS cluster name name component used through out the EKS cluster describing its purpose (ex: dice-dev) | `string` | n/a | yes |
| <a name="input_default_storage_class"></a> [default\_storage\_class](#input\_default\_storage\_class) | The default storage class to use for persistent volumes | `string` | `"gp3-encrypted"` | no |
| <a name="input_keycloak_database"></a> [keycloak\_database](#input\_keycloak\_database) | The name of the database to create in the RDS instance. | `string` | `"bitnami_keycloak"` | no |
| <a name="input_keycloak_password"></a> [keycloak\_password](#input\_keycloak\_password) | The initial password for the database. | `string` | `"bn_keycloak"` | no |
| <a name="input_keycloak_tag"></a> [keycloak\_tag](#input\_keycloak\_tag) | The image tag associated with the keycloak\_chart\_version | `string` | `"22.0.1-debian-11-r30"` | no |
| <a name="input_keycloak_user"></a> [keycloak\_user](#input\_keycloak\_user) | The username for the database. | `string` | `"bn_keycloak"` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | The namespace which will be created and into which keycloak will be deployed. | `string` | `"keycloak"` | no |
| <a name="input_postgresql_tag"></a> [postgresql\_tag](#input\_postgresql\_tag) | The tag of the postgresql image to use. | `string` | `"17.4.0"` | no |
| <a name="input_profile"></a> [profile](#input\_profile) | AWS config profile used to upload images into ECR | `string` | `""` | no |
| <a name="input_service_name"></a> [service\_name](#input\_service\_name) | The name of the service to be deployed in the EKS cluster. | `string` | `"keycloak-service"` | no |
| <a name="input_telemetry_namespace"></a> [telemetry\_namespace](#input\_telemetry\_namespace) | The namespace used for telemetry. | `string` | `"namespace"` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_module_name"></a> [module\_name](#output\_module\_name) | The name of this module. |
| <a name="output_module_version"></a> [module\_version](#output\_module\_version) | The version of this module. |
| <a name="output_namespace"></a> [namespace](#output\_namespace) | The namespace in which keycloak gets installed in. |
| <a name="output_public_endpoint"></a> [public\_endpoint](#output\_public\_endpoint) | The endpoint at which keycloak can be reached from outside the cluster. |
<!-- END_TF_DOCS -->
25 changes: 25 additions & 0 deletions charts/keycloak/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
# img folder
img/
# Changelog
CHANGELOG.md
9 changes: 9 additions & 0 deletions charts/keycloak/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies:
- name: postgresql
repository: oci://registry-1.docker.io/bitnamicharts
version: 16.4.14
- name: common
repository: oci://registry-1.docker.io/bitnamicharts
version: 2.30.0
digest: sha256:df9c08fddaf53b47ff7de5f14b139149d5927009b517268bf5bd93df4cdba87a
generated: "2025-02-28T11:20:53.370359101Z"
Loading
Loading