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