Skip to content

Instantly share code, notes, and snippets.

@salrashid123
salrashid123 / envoy_ekm.md
Last active April 4, 2025 23:08
Envoy EKM : extract the EKM value for a TLS connection with envoy

The following diff extracts the EKM value for a given TLS connection and then surfaces that to LUA (which emits the EKM as a header to the backend)

the LUA config will log the EKM in trace logs

# envoy -c envoy_server.yaml -l trace
[2025-04-04 08:36:29.396][3334775][info][lua] [source/extensions/filters/common/lua/lua.cc:26] script log: >>>>>>>>>>>> EKM: XGurfnlqXyjXphhJrrCmHRoKXAwC7CjrD7vixHdqOIo=

which has the same derived EKM value as a sample client app (eg, golang)

@salrashid123
salrashid123 / openssl_ekm.md
Last active April 3, 2025 11:31
Openssl server and client which prints the EKM
@salrashid123
salrashid123 / openssl_server_tpm.md
Last active March 18, 2025 11:23
openssl server with TPM based private key

TLS with TPM based private key

Requires openssl-tpm2 provider

# export OPENSSL_MODULES=/usr/lib/x86_64-linux-gnu/ossl-modules/
# 
# cat /etc/ssl/openssl.cnf
# [openssl_init]
@salrashid123
salrashid123 / istio_gcp.md
Last active March 8, 2025 13:34
Istio with GCP OIDC Authorization

Simple demo of istio authorization rules using GCP OIDC tokens

Basically, this will allow inbound OIDC authentication and authorization for a service using a google issued id_token

Setup

First install minikube (i'm using kvm2 but you can use anything)

@salrashid123
salrashid123 / attestationkeyauth.go
Last active March 5, 2025 15:18
GCE Attestation Key based authentication
package main
/*
Authenticate to GCP using the GCP embedded vTPM AttestationKey
this specific implementation acquires a JWTAccessToken with scopes
https://github.com/salrashid123/gcp-vtpm-ek-ak/tree/main?tab=readme-ov-file#sign-jwt-with-tpm
1. first create a gce instance with confidentialcompute and vtpm enabled
@salrashid123
salrashid123 / hmacsha256.c
Created February 20, 2025 13:47
hmacsha256 with openssl
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/hmac.h>
@salrashid123
salrashid123 / psk.md
Created February 13, 2025 11:49
TLS PSK with opennsl C
@salrashid123
salrashid123 / csek_versioning.md
Last active January 24, 2025 14:34
GCS CSEK and object versioning

GCS CSEK with Object versioning

The following will upload a file into a bucket with object versioning.

The file will have a CSEK

Then encrypt it with another CSEK and recall the first version using its original CSEK

### create two cseks
@salrashid123
salrashid123 / pcrgen.go
Last active December 12, 2024 22:03
TPM Policy command parameter generation for PCR
package main
import (
"encoding/binary"
"encoding/hex"
"flag"
"io"
"log"
"net"
"os"
@salrashid123
salrashid123 / diy_sts.md
Last active November 24, 2024 14:15
GCP Authentication with custom STS Server

Simple DIY STS server Google Cloud Application Default Credential

or...how to use ADC and run your own STS token broker

An STS server will exchange one token for another. This protocol is used by GCP Workload Federation.

THis example runs your own STS server with GCP where the STS server accepts a source token, validates it and the returns a gcp access_token

For more information about STS servers, see