Skip to content

Instantly share code, notes, and snippets.

@salrashid123
salrashid123 / python_tpm_gcp.md
Last active March 7, 2025 14:35
GCP x509 Workload Federation in pyhton using mTLS and TPM based private key

GCP x509 Workload Federation in python using TPM based authentication and openssl

assume you have a workload federation trusted cert and PEM key (workload3.crt, workload3.key), the following will embed the key into the tpm. Workload federation will use the tpm-based key for mtls.

you can ofcourse create the key inside the tpm or securely import it. those options are described here

Setup TPM tools

@salrashid123
salrashid123 / python_tpm_tls.md
Last active November 21, 2024 21:56
python mtls with TPM based keys and openssl3 provider

Python mTLS client/server with TPM based key

sample client/server webapp in python using mtls where the client key is resident on a trusted platform module

Setup openssl

# on debian 12
@salrashid123
salrashid123 / subjectoken.go
Created November 15, 2024 13:45
Google WorkloadFederation SubjectTokenSupplier sample
/*
simple example of https://pkg.go.dev/golang.org/x/oauth2/google/externalaccount#SubjectTokenSupplier
also see https://github.com/salrashid123/gcp_aws_web_identity
*/
package main
import (
@salrashid123
salrashid123 / gcp_softhsm.md
Last active November 20, 2024 23:56
GCP Enterprise Cert Proxy with SoftHSM

GCP Enterprise Certificate Proxy with SoftHSM

setup of Google Proxies for Enterprise Certificates (GA) with SoftHSM

This sample will embed a device certificate and key into SoftHSM and then access softHSM for mTLS using the GCP proxy.

A default GCS client uses the enterprise proxy transparently to access gcp resources via mTLS


@salrashid123
salrashid123 / peer-metadata-parsing.md
Created November 10, 2024 14:44
Parsing `X-Envoy-Peer-Metadata`

Parsing the x-envoy-peer-metadata field.

eg, in istio outbound

{
  "args": {}, 
  "headers": {
    "Accept-Encoding": "gzip", 
    "Host": "httpbin.org", 
@salrashid123
salrashid123 / bq_keyset.md
Last active October 23, 2024 13:26
bq wrapped keyset

BQ wrapped keyset per row

generate wrapped key per user

bq query --nouse_legacy_sql "
DECLARE kms_resource_name STRING;
SET kms_resource_name = 'gcp-kms://projects/srashid-test2/locations/us/keyRings/bqkr/cryptoKeys/k1';
@salrashid123
salrashid123 / iteratesa.go
Created October 23, 2024 09:27
slowly iterate GCP service accounts in an org for last authentication time
package main
// gcloud auth application-default login
// export USER=`gcloud config get-value core/account`
// export PROJECT_ID=`gcloud config get-value core/project`
// export QUOTA_PROJECT=$PROJECT_ID
// export ORGANIZATION_ID="organizations/1111111"
// gcloud services enable policyanalyzer.googleapis.com
// gcloud projects add-iam-policy-binding --role=roles/serviceusage.serviceUsageConsumer --member=user:$USER $QUOTA_PROJECT
@salrashid123
salrashid123 / parameter.md
Last active October 15, 2024 21:53
go-tpm raw request parameter marshal and unmarshal

encode/decode go-tpm request parameters for use with TPMPolicySyntax

  • github.com/google/go-tpm/tpm2/sessions.go
func CPBytes[R any](cmd Command[R, *R]) ([]byte, error) {
	return cmdParameters(cmd, nil)
}
@salrashid123
salrashid123 / AWS_v4_Signing_noSDK_TPM.md
Last active September 10, 2024 12:20
AWS SigV4 Signing without SDK using Trusted Platform Module (TPM)

AWS v4 signed request using Trusted Platform Module

similar to https://github.com/aws-samples/sigv4-signing-examples but the varaint below invokes sts.GetCallerIdentity where the AWS_SECRET_ACCESS_KEY is embedded in a TPM

In other words, this sample will seal the AWS_SECRET_ACCESS_KEY inside a TPM and then use the TPM to create an AWS v4 signature at no time does the secret leave the TPM but it can be made to issue an hmac

for more info, see

@salrashid123
salrashid123 / AWS_v4_Signing_noSDK.md
Last active September 10, 2024 12:21
AWS SigV4 Signing without SDK