This example assumes you have a Vault instance with the PKI Secrets Engine enabled.
curl -LO https://github.com/testifysec/witness/releases/download/${VERSION}/witness_${VERSION}_${ARCH}.tar.gz
tar -xzf witness_${VERSION}_${ARCH}.tar.gz
In order to create a Witness policy that uses functionaries from Vault's PKI authority we need to retrieve the root certificate from Vault. Make sure to replace the values of the variables to the correct values for your instance of Vault.
export VAULT_ADDR="https://your-vault-instance:8200";
export VAULT_PKI_PATH="example-pki"
export VAULT_NAMESPACE="admin"
export VAULT_ROLE_ID="your-vault-role-id"
export VAULT_ROLE_NAME="my-first-vault-cert"
export VAULT_ROLE_SECRET_ID="your-vault-role-secret-id"
export VAULT_PKI_ISSUER="default"
export VAULT_TOKEN=$(curl -s --header "X-Vault-Namespace: $VAULT_NAMESPACE" \
--request POST --data '{"role_id": "'"$VAULT_ROLE_ID"'", "secret_id": "'"$VAULT_ROLE_SECRET_ID"'"}' \
$VAULT_ADDR/v1/auth/approle/login | jq -r '.auth.client_token' )
export VAULT_ROOT=(curl -s -H "X-Vault-Namespace: $VAULT_NAMESPACE" \
-H "X-Vault-Token: $VAULT_TOKEN" \
"$VAULT_ADDR/v1/$VAULT_PKI_PATH/issuer/$VAULT_PKI_ISSUER/json" \
| jq -r '.data.certificate' | base64)
Next we need to create a Witness policy that includes a step whose functionary must come from our Vault instance. Make sure to replace the vault-pki root certificate with the contents of the VAULT_ROOT
variable, as well as the common name with a common name allowed by your Vault role. Save this as policy.json
.
{
"expires": "2030-12-17T23:57:40-05:00",
"steps": {
"test": {
"name": "test",
"attestations": [
{
"type": "https://witness.dev/attestations/product/v0.1"
}
],
"functionaries": [
{
"type": "root",
"certConstraint": {
"commonname": "hcp-magic.example.com",
"dnsnames": ["*"],
"emails": ["*"],
"organizations": ["*"],
"uris": ["*"],
"roots": [
"vault-pki"
]
}
}
]
}
},
"roots": {
"vault-pki": {
"certificate": "$VAULT_ROOT",
"intermediates": []
}
},
"timestampauthorities": {
"freetsa": {
"certificate": "LS0tLS1CRUdJTiBDRV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6CmFXdWh0cEF0ZDdmZndFYkFTZ3pCN0UrTkdGNHRwVjM3ZThLaUEyeGlHU1JxVDVuZHUyOGZncE9ZODdnRDNBcloKRGN0WnZ2VENmSGRBUzVrRU8zZ25HR2VaRVZMRG1mRXN2OFRHSmEzQWxqVmE1RTQwSVFEc1VYcFFMaThHK1VDNAoxRFdadThFVlQ0cm5ZYUN3MVZYN1NoT1IxUE5DQ3ZqYjhTOHRmZHVkZDl6aFUzZ0VCMHJ4ZGVUeTF0VmJOTFhXCjk5eTkweGN3cjFaSURVd00veFEvbm9POEZSaG0wTG9QQzczRWYrSjRaQmRydld3YXVGM3pKZTMzZDRpYnhFY2IKOC9wejVXekZrZWl4WU0ybnNIaHFIc0JLdzdKUG91S05YUm5sNUlBRTFlRm1xRHlDN0cvVlQ3T0Y2Njl4TTZoYgpVdDVHMjFKRTRjTks2Tk51Y1MrZnpnMUpQWDArM1Zoc1laamo3RDV1bGpSdlFYcko4aUhnci9NNmoyb0xIdlRBCkkyTUxkcTJxalpGRE9DWHN4QnhKcGJtTEdCeDlvdzZaZXJsVXh6d3MyQVd2MnBrPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t"
}
}
}
Now we'll create a key pair to sign and verify the policy with.
openssl genpkey -algorithm ed25519 -outform PEM -out testkey.pem
openssl pkey -in testkey.pem -pubout > testpub.pem
Sign the policy file with the keypair.
witness sign -k testkey.pem -o policy-signed.json -f policy.json
Now we'll run a sample command that shows how we can create an attestation that is signed by a key from Vault's PKI secrets engine and verifiable with our policy.
witness run -s test -o test.json --signer-vault-url="$VAULT_ADDR" \
--signer-vault-pki-secrets-engine-path="$VAULT_PKI_PATH" \
--signer-vault-token="$VAULT_TOKEN" \
--signer-vault-altnames="[email protected]" \
--timestamp-servers="https://freetsa.org/tsr" -- echo "hello" > test.txt
Now all we have to do is ensuer our policy verifies successfully!
witness verify -p policy-signed.json -a test.json -k testpub.pem -f test.txt -l debug