Skip to content
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

Add delegated identity API support to spire-api package #43

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
runs-on: ubuntu-latest
env:
SPIFFE_ENDPOINT_SOCKET: unix:/tmp/spire-agent/public/api.sock
SPIRE_ADMIN_ENDPOINT_SOCKET: unix:/tmp/spire-agent/admin/api.sock
needs: build
steps:
- name: Check out code
Expand Down
32 changes: 32 additions & 0 deletions scripts/agent.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
agent {
data_dir = "./data/agent"
log_level = "DEBUG"
trust_domain = "example.org"
server_address = "localhost"
server_port = 8081

# Insecure bootstrap is NOT appropriate for production use but is ok for
# simple testing/evaluation purposes.
insecure_bootstrap = true

admin_socket_path = "$STRIPPED_SPIRE_ADMIN_ENDPOINT_SOCKET"
authorized_delegates = [
"spiffe://example.org/myservice",
]
}

plugins {
KeyManager "disk" {
plugin_data {
directory = "./data/agent"
}
}

NodeAttestor "join_token" {
plugin_data {}
}

WorkloadAttestor "unix" {
plugin_data {}
}
}
14 changes: 14 additions & 0 deletions scripts/run-spire.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Constants
spire_version="1.7.1"
spire_folder="spire-${spire_version}"
Expand Down Expand Up @@ -35,6 +37,9 @@ mkdir -p /tmp/spire-server
bin/spire-server run -config conf/server/server.conf > "${spire_server_log_file}" 2>&1 &
wait_for_service "bin/spire-server healthcheck" "SPIRE Server" "${spire_server_log_file}"

export STRIPPED_SPIRE_ADMIN_ENDPOINT_SOCKET=$(echo $SPIRE_ADMIN_ENDPOINT_SOCKET| cut -c6-)
cat $SCRIPT_DIR/agent.conf | envsubst > "conf/agent/agent.conf"

# Run the SPIRE agent with the joint token
bin/spire-server token generate -spiffeID ${agent_id} > token
cut -d ' ' -f 2 token > token_stripped
Expand All @@ -48,4 +53,13 @@ for service in "myservice" "myservice2"; do
sleep 10 # Derived from the default Agent sync interval
done


uid=$(id -u)
# The UID in the test has to match this, so take the current UID and add 1
uid_plus_one=$((uid + 1))
# Register a different UID with the SPIFFE ID "spiffe://example.org/different-process" with a TTL of 5 seconds
bin/spire-server entry create -parentID ${agent_id} -spiffeID spiffe://example.org/different-process -selector unix:uid:${uid_plus_one} -ttl 5
sleep 10


popd
2 changes: 1 addition & 1 deletion spiffe/src/workload_api/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl WorkloadApiClient {
.get(DEFAULT_SVID)
.ok_or(ClientError::EmptyResponse)
.and_then(|r| {
JwtSvid::from_str(&r.svid).map_err(|err| ClientError::InvalidJwtSvid(err))
JwtSvid::from_str(&r.svid).map_err(ClientError::InvalidJwtSvid)
})
}

Expand Down
7 changes: 6 additions & 1 deletion spire-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ categories = ["cryptography"]
keywords = ["SPIFFE", "SPIRE"]

[dependencies]
spiffe = { version = "0.3.1", path = "../spiffe" }
bytes = { version = "1", features = ["serde"] }
spiffe = { path = "../spiffe" }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that the crates in this repository will be versioned independently, it would be prudent to pin the spiffe dependency to a specific version when publishing the spire-api crate. This ensures that anyone using a published version of the spire-api crate will receive a consistent and known-good version of the spiffe crate. By explicitly specifying the version, we maintain control over the compatibility of the dependencies.

tonic = { version = "0.9", default-features = false, features = ["prost", "codegen", "transport"]}
prost = { version = "0.11"}
prost-types = {version = "0.11"}
tokio = { "version" = "1", features = ["net", "test-util"]}
tokio-stream = "0.1"
tower = { version = "0.4", features = ["util"] }

[dev-dependencies]
once_cell = "1.18"

[build-dependencies]
tonic-build = { version = "0.9", default-features = false, features = ["prost"] }
Expand Down
Loading