-
Notifications
You must be signed in to change notification settings - Fork 476
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
spire-agent: re-attest without restarting #4991
Changes from all commits
33309f4
110d299
4a09e57
6f495f6
3a50920
9eebedb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ import ( | |
|
||
type Rotator interface { | ||
Run(ctx context.Context) error | ||
Reattest(ctx context.Context) error | ||
|
||
State() State | ||
Subscribe() observer.Stream | ||
|
@@ -137,6 +138,29 @@ func (r *rotator) SetRotationFinishedHook(f func()) { | |
r.rotationFinishedHook = f | ||
} | ||
|
||
func (r *rotator) Reattest(ctx context.Context) (err error) { | ||
state, ok := r.state.Value().(State) | ||
if !ok { | ||
return fmt.Errorf("unexpected value type: %T", r.state.Value()) | ||
} | ||
|
||
if state.Reattestable { | ||
if !r.c.DisableReattestToRenew { | ||
err = r.reattest(ctx) | ||
} else { | ||
return errors.New("re-attestation is disabled") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure about this error, since a user must DIsableReattesttion to get into this case...
and if that is the case this code is pretty much the same that is in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what i had before and @amartinezfayo asked me to change. Either way is fine with me.
|
||
} | ||
} else { | ||
return errors.New("attestation method is not re-attestable") | ||
} | ||
|
||
if err == nil && r.rotationFinishedHook != nil { | ||
r.rotationFinishedHook() | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (r *rotator) rotateSVIDIfNeeded(ctx context.Context) (err error) { | ||
state, ok := r.state.Value().(State) | ||
if !ok { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
#!/bin/bash | ||
|
||
log-debug "bootstrapping agent..." | ||
docker-compose exec -T spire-server \ | ||
/opt/spire/bin/spire-server bundle show > conf/agent/bootstrap.crt | ||
|
||
MAXCHECKS=30 | ||
CHECKINTERVAL=1 | ||
for ((i=1;i<=MAXCHECKS;i++)); do | ||
log-info "trying to bootstrap agent ($i of $MAXCHECKS max)..." | ||
docker-compose logs spire-agent | ||
if docker-compose exec -T spire-server \ | ||
/opt/spire/bin/spire-server bundle show > conf/agent/bootstrap.crt; then | ||
exit 0 | ||
fi | ||
sleep "${CHECKINTERVAL}" | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
#!/bin/bash | ||
|
||
log-debug "starting agent again..." | ||
|
||
docker-up spire-agent | ||
|
||
# Check at most 30 times (with one second in between) that the agent is back up | ||
MAXCHECKS=30 | ||
CHECKINTERVAL=1 | ||
for ((i=1;i<=MAXCHECKS;i++)); do | ||
log-info "checking that the agent is back up ($i of $MAXCHECKS max)..." | ||
docker-compose logs spire-agent | ||
if docker-compose logs spire-agent | grep "Starting Workload and SDS APIs"; then | ||
exit 0 | ||
fi | ||
sleep "${CHECKINTERVAL}" | ||
done |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
|
||
log-debug "deleting agent..." | ||
|
||
# Check at most 30 times (with one second in between) that we can evict the agent, it may take a while for it to start up | ||
MAXCHECKS=30 | ||
CHECKINTERVAL=1 | ||
for ((i=1;i<=MAXCHECKS;i++)); do | ||
log-info "attempting to evict agent ($i of $MAXCHECKS max)..." | ||
if docker-compose exec -T spire-server \ | ||
/opt/spire/bin/spire-server agent evict \ | ||
-spiffeID "spiffe://domain.test/spire/agent/x509pop/$(fingerprint conf/agent/agent.crt.pem)"; then | ||
exit 0 | ||
fi | ||
sleep "${CHECKINTERVAL}" | ||
done | ||
|
||
|
||
# Check at most 30 times (with one second in between) that the agent has to re-attest | ||
MAXCHECKS=30 | ||
CHECKINTERVAL=1 | ||
for ((i=1;i<=MAXCHECKS;i++)); do | ||
log-info "checking for agent to get notification and try to reattest ($i of $MAXCHECKS max)..." | ||
docker-compose logs spire-agent | ||
if docker-compose logs spire-agent | grep "Agent needs to re-attest; will attempt to re-attest"; then | ||
exit 0 | ||
fi | ||
sleep "${CHECKINTERVAL}" | ||
done | ||
|
||
# Check at most 30 times (with one second in between) that the agent has re-attested | ||
MAXCHECKS=30 | ||
CHECKINTERVAL=1 | ||
for ((i=1;i<=MAXCHECKS;i++)); do | ||
log-info "checking for agent to get notification and try to reattest ($i of $MAXCHECKS max)..." | ||
docker-compose logs spire-agent | ||
if docker-compose logs spire-agent | grep "Successfully reattested node"; then | ||
exit 0 | ||
fi | ||
sleep "${CHECKINTERVAL}" | ||
done | ||
|
||
fail-now "timed out waiting for agent to shut down" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,7 @@ docker-compose exec -T spire-server \ | |
/opt/spire/bin/spire-server agent evict -spiffeID $AGENT_B_SPIFFE_ID || fail-now "failed to evict agent b." | ||
|
||
check-evict-agents $AGENT_A_SPIFFE_ID $AGENT_B_SPIFFE_ID | ||
check-attested-agents | ||
|
||
# spire-agent-a will re-attest but spire-agent-b won't because join_token implements trust on first use model. | ||
AGENT_A_SPIFFE_ID_PATH="/spire/agent/x509pop/$(fingerprint conf/agent/agent.crt.pem)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you move this PATH at the start and use it to create AGENT_A_SPIFFE_ID? |
||
check-attested-agents $AGENT_A_SPIFFE_ID_PATH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add unit tests for this new function?