Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
798e263
Add files for private CA
sudo-rgorai Jun 22, 2023
84a9e1d
Take AWS region as input
sudo-rgorai Jun 23, 2023
1e8aa25
Remove action for generating root X.509 certificate
sudo-rgorai Jun 24, 2023
123b832
Use current timestamp for auth header
sudo-rgorai Jun 24, 2023
ce72f23
Accept lambda event as params
sudo-rgorai Jun 24, 2023
571e245
Use region for all aws services
sudo-rgorai Jun 26, 2023
abcbce9
Use exact pattern matching for deleting temporary files
sudo-rgorai Jun 26, 2023
af7756d
Fix filenames in deploy-resources.sh
sudo-rgorai Jun 26, 2023
2e1b9b7
Change CA action from get to generate
sudo-rgorai Jun 26, 2023
8039e58
Delete secret.json after use
sudo-rgorai Jun 26, 2023
ba4deb7
Delete package-lock.json
sudo-rgorai Jun 26, 2023
e27dff0
Fix ssh client cert validity
sudo-rgorai Jun 26, 2023
c30758f
Use pubkey file instead of string for generating certificate
sudo-rgorai Jun 26, 2023
99afb54
Do not use response.json
sudo-rgorai Jun 26, 2023
eb67f93
Base64 encode response certificate
sudo-rgorai Jul 4, 2023
99a8b9b
Invoke function using lambda URL instead of AWS CLI
sudo-rgorai Jul 4, 2023
b9c2c48
Add -h help tag and handle invalid action
sudo-rgorai Jul 6, 2023
d38a12c
Certificate validity should be decided by CA not by the subject
sudo-rgorai Jul 6, 2023
1b7802e
Check for existing certificates and their expiration
sudo-rgorai Jul 6, 2023
4c70c44
Add certificate expiration buffer of 5 minutes
sudo-rgorai Jul 7, 2023
6efcdb3
Use awscurl instead of curl to generate certs
sudo-rgorai Jul 11, 2023
ff72a42
Do not use awscurl
sudo-rgorai Jul 11, 2023
c854587
reorganize directories
Jul 11, 2023
d67a780
add awsprofile, let server decide it's own secret region
Jul 11, 2023
e073fbc
Add audience header
sudo-rgorai Jul 12, 2023
b4f21c5
Use docker container
sudo-rgorai Jul 12, 2023
b078b61
Fix server deployment issues
sudo-rgorai Jul 13, 2023
6424640
Add instruction for AWS secrets region environment variable
sudo-rgorai Jul 14, 2023
a128e39
Specify certificate type
sudo-rgorai Jul 14, 2023
d4fdede
private-ca: use variables for validity, cert details
Aug 4, 2023
28b4de3
merge main
Aug 4, 2023
2720292
Added cron job to Docker Container to regenerate certs everyday
Sep 25, 2023
23f4391
added override default cert location for curl
Sep 25, 2023
312cda7
workflow to push private ca container to docker hub
Oct 6, 2023
9df7571
updated push path for privateCA workflow
Oct 13, 2023
dfa428c
fix: set curl cert bundle path
Oct 26, 2023
315bc95
fix: changed cd path [skip ci]
Oct 26, 2023
b62be6a
fix: filter out comment lines from ssh-keyscan output in verify-finge…
Harshit-RV May 21, 2025
b5c0707
Improve AWS metadata handling, SSH cert principals, and Docker Alpine…
Harshit-RV May 30, 2025
de78c36
Update Docker README
Harshit-RV May 30, 2025
ec42fb1
fix: remove X.509 certificate generation from client and update README
Harshit-RV May 30, 2025
266f584
Merge branch 'main' into update/privateCA
Harshit-RV May 30, 2025
c8aa3a1
CI: bumps ssm-env-util to 1.0.1-update/privateCA.0
May 30, 2025
0dbe931
Merge branch 'main' into update/privateCA
Harshit-RV May 30, 2025
d47032f
fix: parameter index in generate-certificate scripts
Harshit-RV Jun 2, 2025
96c2037
fix: generate certificate using AWS CLI script
Harshit-RV Jun 2, 2025
00612e8
feat: update script for cert generation using AWS CLI script to have …
Harshit-RV Jun 3, 2025
be000a0
fix: use virtual env Python binary in generate-certificate-curl.sh
Harshit-RV Jun 3, 2025
e1042c9
refactor: restructure private-ca client - remove Docker subdirectory
Harshit-RV Jun 3, 2025
efe0fa5
clean up outdated comments
Harshit-RV Jun 3, 2025
65c0100
feat: add function to get temp AWS creds based on the environment and…
Harshit-RV Jun 4, 2025
89452dc
refactor: update generate-certificate-curl.sh for improved AWS creden…
Harshit-RV Jun 4, 2025
712af90
update README, Dockerfile, change parameter index
Harshit-RV Jun 5, 2025
4f8df0b
update README.md
Harshit-RV Jun 5, 2025
2343465
chore: migrate aws-sdk to v3 in Private CA
Harshit-RV Jun 6, 2025
f2068ca
prevent host cert generation in client environments
Harshit-RV Jun 6, 2025
1bd830f
refactor: update generate-certificate-aws-cli.sh for improved AWS cre…
Harshit-RV Jun 6, 2025
698d95e
refactor: improve AWS credential handling by removing redundant decla…
Harshit-RV Jun 9, 2025
41037d7
update README.md: add instructions for generating certificates via A…
Harshit-RV Jun 9, 2025
4e15f38
update README.md
Harshit-RV Jun 9, 2025
3ce024f
update README with ENVIRONMENT param usage and client environment lim…
Harshit-RV Jun 9, 2025
78f449f
feat: add function to get public IP of host using Describe Instances …
Harshit-RV Jun 20, 2025
6fbe55e
fix: if check for root privileges for host certificate generation in …
Harshit-RV Jun 20, 2025
749622d
add update-private-ca-lambda workflow for AWS Lambda updates and remo…
Harshit-RV Jun 20, 2025
bfe98ff
update generate cert using AWS CLI script: remove public IP from cert…
Harshit-RV Jun 20, 2025
20d1841
update: use UTC timezone for certificate timestamps to avoid comparis…
Harshit-RV Jun 20, 2025
fdf291a
update private CA workflows and improve error messages in certificate…
Harshit-RV Jun 23, 2025
d7345b5
update README: merge client and root README files
Harshit-RV Jun 23, 2025
1f162ee
update timezone in aws-auth-header: use UTC, improve error messages f…
Harshit-RV Jun 23, 2025
2331c14
update README and Dockerfile: remove unnecessary dependencies
Harshit-RV Jun 23, 2025
1235a14
update update-private-ca-lambda workflow: upgrade AWS credentials act…
Harshit-RV Jun 23, 2025
abfd442
fix generate-certificate-aws-cli script: correct error message format…
Harshit-RV Jun 23, 2025
34a2cd1
update private-ca workflow: modify path to include all subdirectories…
Harshit-RV Jun 24, 2025
ebd2376
rename private CA client venv to 'private-ca-client-env'
Harshit-RV Jun 24, 2025
1c6fa9d
chore: document logic for adding host CA public key to known_hosts
Harshit-RV Jun 24, 2025
02343fb
refactor: simplify getPublicIpAddress function signature
Harshit-RV Jun 24, 2025
aa3937c
quiet zip output to keep logs clean
Harshit-RV Jun 24, 2025
27d9e52
add error handling and validation in private CA lambda
Harshit-RV Jun 24, 2025
7959f05
restore non-related file changes to match main branch version
Harshit-RV Jun 24, 2025
e9b981a
refactor: use JSON.stringify for certificate bodies
Harshit-RV Jun 24, 2025
6387338
refactor: remove commented-out updateSecret function from secret-mana…
Harshit-RV Jun 24, 2025
ebf6fd2
fix: return exit code 1 in certificate generation scripts in case of …
Harshit-RV Jun 24, 2025
458dde1
chore: use Ubuntu 24.04 for the update-private-ca-lambda job
Harshit-RV Jun 24, 2025
3119656
fix: redirect output of update-server-on-lambda script to suppress logs
Harshit-RV Jun 24, 2025
943908b
refactor: remove unused SSL key and certificate generation from deplo…
Harshit-RV Jun 24, 2025
57a0c8c
build: use esbuild for bundling and related changes in deployment scr…
Harshit-RV Jun 25, 2025
5c80d21
fix: add error handling for invalid ARN format
Harshit-RV Jun 25, 2025
0c44b21
fix: improve AWS credentials check for adding profile arg in lambda i…
Harshit-RV Jun 25, 2025
e222171
fix: update AWS credentials check to use USER_AWS_DIR var for profile…
Harshit-RV Jun 25, 2025
b8054a6
fix: remove output suppression from Lambda update command to show errors
Harshit-RV Jun 25, 2025
03f50f7
feat: derive secret ID from account ID, return error if secret not fo…
Harshit-RV Jun 25, 2025
cbffd0d
fix: show error body and HTTP status code on Lambda request failure
Harshit-RV Jun 25, 2025
f3a055d
fix: improve error handling for Lambda invocation by capturing invoca…
Harshit-RV Jun 25, 2025
e900bb9
update secret name in deployment script, remove set -e from scripts, …
Harshit-RV Jun 25, 2025
ac1f8b7
feat: add script and policies for creating IAM roles and policies for…
Harshit-RV Jun 25, 2025
2f91f4d
chore: update IAM role and policy names in create-role-action and in …
Harshit-RV Jun 25, 2025
79b469b
fix: changed AWS_PROFILE_ARG logic from credentials/config check to e…
Harshit-RV Jun 30, 2025
ff403a5
feat: add script to retrieve authorized principals from AWS EC2 metad…
Harshit-RV Jul 2, 2025
a6b5d90
feat: add date formatting utility and update SSH cert generation to u…
Harshit-RV Jul 2, 2025
fe0b3c8
fix [major]: remove RBAC using ENV tag of EC2 hosts and revert SSH ce…
Harshit-RV Jul 2, 2025
1de518e
refactor: migrate to TypeScript, restructure project
Harshit-RV Jul 3, 2025
f522461
docs: update README to remove note about AWS_SECRETS_REGION env variable
Harshit-RV Jul 3, 2025
a6dfa8b
refactor: remove secretPrefix param from getSecret function
Harshit-RV Jul 3, 2025
eeeaa4b
fix: update AWS_REGION and AWS_PROFILE defaults in deployment script
Harshit-RV Jul 3, 2025
684dcdb
feat: add getHostCAPublicKey action in private-ca lambda
Harshit-RV Jul 7, 2025
9947763
feat: add script to retrieve host CA public key and update known_host…
Harshit-RV Jul 8, 2025
e371e4b
chore: remove debug echo statement for AWS credentials in get-host-ca…
Harshit-RV Jul 8, 2025
c98e6d3
chore: disable pip version check when upgrading boto3 in generate-cer…
Harshit-RV Jul 9, 2025
832a4c7
chore: disable pip version check in certificate generation scripts
Harshit-RV Jul 9, 2025
4f5461e
make user SSH and AWS directory paths cross-platform by using $HOME
Harshit-RV Jul 9, 2025
a2a448d
feat: remove validity check for host cert, add cleanup function for e…
Harshit-RV Jul 9, 2025
ae2a2ea
refactor generate-certificate-curl.sh/clean_config_on_error function
Harshit-RV Jul 9, 2025
caca115
feat (get-host-ca-public-key): early return in case of existing Host …
Harshit-RV Jul 9, 2025
0ffda0f
feat (generate-certificate-curl.sh): Add check for AWS credentials as…
Harshit-RV Jul 10, 2025
3532838
refactor (generate-certificate-curl.sh): update AWS credentials retri…
Harshit-RV Jul 10, 2025
521037b
validity check for host certs, safer way to replace old cert with new…
Harshit-RV Jul 17, 2025
4fa2142
safe replacement of old user certs with new ones
Harshit-RV Jul 17, 2025
d2c8987
add support for multiple CAs on both host and user side
Harshit-RV Jul 17, 2025
35808c6
feat (generate-certificate-curl.sh): check for known_hosts entry alon…
Harshit-RV Jul 18, 2025
42750e8
improve certificate validity check to consider next cron run timing
Harshit-RV Jul 22, 2025
e65abbc
update default validity period for host SSH certificates to 7 days
Harshit-RV Jul 22, 2025
b2bcf45
chore: default profile to empty string
giriparus Jul 23, 2025
01eab60
remove profile param, add check for cert file before deleting if RSA …
Harshit-RV Jul 23, 2025
f745ef3
refactor: update CA keys comment, remove dependency on get-credential…
Harshit-RV Jul 23, 2025
74c4387
remove node-forge dependency
Harshit-RV Jul 23, 2025
9cb6dc8
fix: update format for current_timestamp var to use epoch time
Harshit-RV Jul 23, 2025
c1740ff
fix: correct identifier of user CA public key
Harshit-RV Jul 24, 2025
a77f2f7
refactor: update echo msgs
Harshit-RV Jul 24, 2025
b670a5d
refactor [major]: create reusable functions and remove duplicate code
Harshit-RV Jul 24, 2025
4a1396a
fix: update usage instructions in generate-certificate-curl.sh
Harshit-RV Jul 24, 2025
7da5c75
update AWS region defaults to eu-central-1
Harshit-RV Jul 24, 2025
a415969
refactor: remove default values of CA Action and URL
Harshit-RV Jul 24, 2025
79734b3
refactor: use date-fns dependency and remove custom date formatting
Harshit-RV Jul 24, 2025
982f410
refactor: rename generate-certificate-curl.sh to invoke-private-ca.sh…
Harshit-RV Jul 24, 2025
edd6775
refactor [major]: update AWS-CLI script, rename to invoke-private-ca-…
Harshit-RV Jul 24, 2025
7632221
refactor (private-ca-server): rename certificate generation functions…
Harshit-RV Jul 24, 2025
a46ae71
refactor: add cert validity param and update half-life calculation
Harshit-RV Jul 25, 2025
418bbbd
Update private-ca/server/src/get-public-ip-address.ts
giriparus Jul 25, 2025
ff0d72b
Update private-ca/server/src/secret-manager-utils.ts
giriparus Jul 25, 2025
b2cb20f
Update private-ca/server/src/index_lambda.ts
giriparus Jul 25, 2025
faaffea
refactor: add cert half-life param with default value as 3 days, remo…
Harshit-RV Jul 25, 2025
566f230
fix: update script name in Dockerfile
Harshit-RV Jul 25, 2025
08e9d2e
update README
Harshit-RV Jul 25, 2025
1fb84fd
refactor: reorder EC2-region param
Harshit-RV Jul 25, 2025
b0cb5c4
refactor: simplify cert half life calculation
Harshit-RV Jul 25, 2025
a9472fd
fix: do not delete cert and user_ca files if cert is invalid, only cl…
Harshit-RV Jul 25, 2025
750be83
update instructions in invoke-private-ca scripts to include new param…
Harshit-RV Jul 25, 2025
f4c4d0c
fix: read AWS_REGION from vars instead of secrets in update-private-c…
Harshit-RV Jul 25, 2025
2fe5da1
chore: add environment specification for update-private-ca-lambda wor…
Harshit-RV Jul 25, 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
34 changes: 34 additions & 0 deletions .github/workflows/update-private-ca-lambda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Update Private CA Lambda on push

on:
push:
branches:
- main
paths:
- private-ca/server/**
- .github/workflows/update-private-ca-lambda.yml

permissions:
id-token: write
contents: read

jobs:
update-lambda:
runs-on: "ubuntu-24.04"
environment: "Prod"

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

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_PRIVATE_CA_LAMBDA_UPDATE_ROLE }}
role-session-name: UpdatePrivateCALambda

- name: Run update-server-on-lambda.sh
run: |
cd private-ca/
bash update-server-on-lambda.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/node_modules/**
27 changes: 27 additions & 0 deletions action/setup/create-role-action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ACCOUNT_ID=$1
PROFILE=$2
POLICY_NAME=${3:-AWS_PRIVATE_CA_LAMBDA_UPDATE_POLICY}
ROLE_NAME=${4:-AWS_PRIVATE_CA_LAMBDA_UPDATE_ROLE}

[ ! -z $PROFILE ] && PROFILE="--profile=$PROFILE"

ROLE_ARN=$(aws iam list-roles --query "Roles[?RoleName=='$ROLE_NAME'].Arn" --output text $PROFILE)

if [ -n "$ROLE_ARN" ] ; then
echo "Role $ROLE_NAME already exists"
else
ASSUME_ROLE_POLICY_DOC=$( sed "s/<account-id>/$ACCOUNT_ID/" policies/trust-relationship-policy.json )
ROLE_ARN=$(aws iam create-role --role-name "$ROLE_NAME" --assume-role-policy-document "$ASSUME_ROLE_POLICY_DOC" --output text $PROFILE --query 'Role.Arn')
echo "Role created with arn: "
echo $ROLE_ARN
fi

POLICY_ARN=$(aws iam list-policies --query "Policies[?PolicyName=='$POLICY_NAME'].Arn" --output text $PROFILE)
if [ -n "$POLICY_ARN" ]; then
echo "Policy $POLICY_NAME already exists"
else
echo "Creating Policy"
POLICY_DOC=$(sed -e "s/<account_id>/$ACCOUNT_ID/g" policies/lambda-update-policy.json)
POLICY_ARN=$(aws iam create-policy --policy-name $POLICY_NAME --policy-document "$POLICY_DOC" $PROFILE --output text --query 'Policy.Arn' )
aws iam attach-role-policy --role-name "$ROLE_NAME" --policy-arn $POLICY_ARN $PROFILE
fi
15 changes: 15 additions & 0 deletions action/setup/policies/lambda-update-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"lambda:UpdateFunctionCode",
"lambda:GetFunction"
],
"Resource": [
"arn:aws:lambda:*:<account_id>:function:privateCA"
]
}
]
}
20 changes: 20 additions & 0 deletions action/setup/policies/trust-relationship-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<account-id>:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
},
"StringLike": {
"token.actions.githubusercontent.com:sub": "repo:getfundwave/network-utils:environment:Prod"
}
}
}
]
}
160 changes: 160 additions & 0 deletions private-ca/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Private Certificate Authority (CA) for SSH Certificates

This project provides a private Certificate Authority (CA) implementation for generating SSH certificates. It allows you to issue certificates for SSH hosts and users for secure communication.

## Deployment

Deploy the resources by running:

```bash
./deploy-server-on-lambda.sh
```

This creates the following resources on AWS:

- Secret to store the keys for signing certificates
- A role for the lambda function
- A policy to be attached to the role giving read access to created secret
- An openSSH layer to facilitate SSH operations
- The lambda function to act as a privateCA

## Prerequisites for usage

### Running via Docker (for host machines only)

- Docker

### Running directly

- Python 3
- Bash
- Dependencies: `curl`, `jq`, `ssh-keygen`, `base64`

### Running via AWS CLI (Lambda)

- AWS CLI
- Python 3
- Access to the Lambda function in the specified region

## Usage

### Running directly

#### For client certificates:

```bash
bash invoke-private-ca.sh generateClientSSHCert <PRIVATE-CA-URL> client
```

#### For host certificates:

```bash
bash invoke-private-ca.sh generateHostSSHCert <PRIVATE-CA-URL> host
```

#### For getting host CA public key:

```bash
bash invoke-private-ca.sh getHostCAPublicKey <PRIVATE-CA-URL> client
```

**Note:**

1. Sudo privilege is required for generating host certificates as they need to write to system directories like `/etc/ssh`.
2. The `ENVIRONMENT` (host or client) parameter affects how AWS credentials are retrieved. See [Script Parameters](#script-parameters) for more details.

### Running via AWS CLI (Lambda)

The `invoke-private-ca-aws-cli.sh` script provides an alternative approach to generate certificates. This method uses AWS CLI to invoke the Lambda function rather than making HTTP requests.

#### Usage:

```bash
bash invoke-private-ca-aws-cli.sh <CA_ACTION> <ENVIRONMENT> <USER-SSH-DIR> <SYSTEM-SSH-DIR> <CA-LAMBDA-FUNCTION-NAME> <LAMBDA-REGION> <AWS-STS-REGION> <AWS-EC2-REGION> <CERT-HALF-LIFE-SECONDS>
```

### Running via Docker

1. Build the Docker image:

```bash
cd client
docker build -t certificate-generator .
```

2. Run the Docker container with the required volume mounts and parameters:

```bash
docker run --rm \
-v $HOME/.ssh:/root/.ssh \
-v /etc/ssh:/etc/ssh \
certificate-generator \
generateHostSSHCert \
https://<PRIVATE-CA-URL>/ \
host \
```

## Running as a cron job (optional)

Since certificates need to be renewed periodically, you can set up a cron job to automatically regenerate them.

Sample script:

```bash
#!/bin/bash

# Create the cron job entry
echo "* */1 * * * cd /path/to/private-ca/client && bash invoke-private-ca.sh generateHostSSHCert https://<PRIVATE-CA-URL>/ host >> /home/cron.log 2>&1" > /tmp/root_crontab

# Load into root's crontab
crontab -u root /tmp/root_crontab

# Optionally start cron service (only if not already running)
systemctl start cron 2>/dev/null || systemctl start crond 2>/dev/null
```

## Script Parameters

Both `invoke-private-ca.sh` and `invoke-private-ca-aws-cli.sh` accept several shared and some script-specific parameters.

| Parameter | Required | Description | Used In Script(s) | Default Value |
| ------------------------- | -------- | ------------------------------------------------------------------------------------------ | ------------------------------ | ------------------------- |
| `CA_ACTION` | Yes | Action to perform: `generateClientSSHCert`, `generateHostSSHCert`, or `getHostCAPublicKey` | Both | — |
| `CA_URL` | Yes | URL of the Private CA | `invoke-private-ca.sh` | — |
| `ENVIRONMENT` | No | Machine environment: `"client"` (uses AWS CLI) or `"host"` (uses EC2 metadata) | Both | `client` |
| `USER_SSH_DIR` | No | Path to user's SSH directory | Both | `$HOME/.ssh` |
| `USER_AWS_DIR` | No | Path to user's AWS directory | `invoke-private-ca.sh` | `$HOME/.aws` |
| `SYSTEM_SSH_DIR` | No | Path to system SSH directory | Both | `/etc/ssh` |
| `AWS_STS_REGION` | No | AWS region to use for STS operations | Both | `eu-central-1` |
| `LAMBDA_REGION` | No | AWS region where the Lambda function is deployed | `invoke-private-ca-aws-cli.sh` | `eu-central-1` |
| `CA_LAMBDA_FUNCTION_NAME` | No | Name of the Lambda function that performs certificate signing | `invoke-private-ca-aws-cli.sh` | `privateCA` |
| `AWS_EC2_REGION` | No | AWS region where the EC2 instance is deployed | `invoke-private-ca-aws-cli.sh` | `eu-central-1` |
| `CERT_HALF_LIFE_SECONDS` | No | Certificate half-life in seconds | Both | `259200 seconds (3 days)` |

## Important Notes

- **Certificate Type**: Determined by the `CA_ACTION` parameter (`generateClientSSHCert`, `generateHostSSHCert`, or `getHostCAPublicKey`)
- **Permissions**: Host certificates require sudo privileges for system directory access
- **Public Key Retrieval**: The `getHostCAPublicKey` action retrieves the Host CA's public key for host certificate verification

## Client Environment Limitations

**Important**: Client environments can only generate client certificates because they don't have a public IP address.

- **Host Certificate Requirements**: Host certificates require the public IP address as a hostname when issuing the certificate. Due to the absence of a public IP address, client environments cannot generate host certificates
- **Recommendation**: Use client environments exclusively for generating client certificates, and use host environments (such as EC2 instances with public IPs) for generating host certificates

## Directory Structure

- `deploy-server-on-lambda.sh`: Script to deploy the Lambda function and related AWS resources
- `update-server-on-lambda.sh`: Script to update the deployed Lambda function
- `client/`: Directory containing client-side tools
- `invoke-private-ca.sh`: Main script for certificate generation using curl
- `invoke-private-ca-aws-cli.sh`: Alternative script using AWS CLI
- `aws-auth-header.py`: Python helper for generating AWS authentication headers
- `Dockerfile`: Docker container configuration
- `server/`: Directory containing server-side Lambda function code

```

```
12 changes: 12 additions & 0 deletions private-ca/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM alpine:3.18.3

RUN apk add bash curl jq python3 openssh

WORKDIR /app

COPY invoke-private-ca.sh .
COPY aws-auth-header.py .

RUN chmod +x invoke-private-ca.sh

ENTRYPOINT ["bash", "invoke-private-ca.sh"]
29 changes: 29 additions & 0 deletions private-ca/client/aws-auth-header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sys
from datetime import datetime, timezone
from botocore.auth import SigV4Auth
from botocore.awsrequest import AWSRequest
from botocore.credentials import Credentials

if __name__ == "__main__":
access_key_id = sys.argv[1]
secret_access_key = sys.argv[2]
session_token = sys.argv[3]
aws_region = sys.argv[4]

sts_host = "sts." + aws_region + ".amazonaws.com"
request_parameters = 'Action=GetCallerIdentity&Version=2011-06-15'
request_headers = {
'Host': sts_host,
'X-Amz-Date': datetime.now(timezone.utc).strftime('%Y%m%dT%H%M%SZ'),
'Aud': 'FundwaveCA'
}
request = AWSRequest(method="POST", url="/", data=request_parameters, headers=request_headers)
boto_creds = Credentials(access_key_id, secret_access_key,token=session_token)
auth = SigV4Auth(boto_creds, "sts", aws_region)
auth.add_auth(request)

authorization = request.headers["Authorization"]
date = request.headers["X-Amz-Date"]

response = f'{{"Authorization": "{authorization}", "Date": "{date}"}}'
print(response)
Loading