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

SyncAuthorizedEntries: fix issue with entry id reuse and add integration test #5764

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sorindumitru
Copy link
Collaborator

Pull Request check list

  • Commit conforms to CONTRIBUTING.md?
  • Proper tests/regressions included?
  • Documentation updated?

Affected functionality
Registration entry synchronization between agent and server.

Description of change
The agent will now include the created_at field when determining if a registration entry is stale or not.

Which issue this PR fixes
fixes #5522
fixes #5686
depends on spiffe/spire-api-sdk#69

@sorindumitru sorindumitru force-pushed the sync-authorized-entries-fix branch 4 times, most recently from 2c70eaa to fdbf9c4 Compare January 16, 2025 18:24
@sorindumitru sorindumitru marked this pull request as ready for review January 16, 2025 18:24
@sorindumitru sorindumitru force-pushed the sync-authorized-entries-fix branch from 3c68348 to ca3db54 Compare January 21, 2025 13:40
return true
}

// TODO: remove in SPIRE 1.14
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a bug to track this?

return false
}

if entry.CreatedAt != revisionCreatedAt {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add comments about why this is required?

@@ -1136,16 +1147,7 @@ type testServer struct {
}

func checkAuthorizedEntryOutputMask(outputMask *types.EntryMask) error {
if diff := cmp.Diff(outputMask, &types.EntryMask{
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a personal preference, but could you keep the hardcoded expected mask? The reason is to prevent accidental updates to the default one. If we decide to update the default mask, we should intentionally update this one as well as a security check.

Comment on lines 7 to 16
for id in $(seq 1 512); do
ENTRIES=$(jq \
--arg uidselector "uid:${id}"\
--arg spiffeID "spiffe://domain.test/workload${id}"\
'.entries[.entries| length] |= . + {
"parent_id": "spiffe://domain.test/node",
"spiffe_id": $spiffeID,
"selectors": [{"type": "unix", "value": $uidselector}]
}' <<< ${ENTRIES})
done
Copy link
Collaborator

Choose a reason for hiding this comment

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

all entry creation can be simplified with something like this:

ENTRIES=$(jq -n '{
    entries: [
        {
            parent_id: "spiffe://domain.test/node",
            spiffe_id: "spiffe://domain.test/theworkload",
            selectors: [
                {
                    type: "unix",
                    value: "uid:0"
                }
            ] 
        },
        (
            range(1; 512) | {
                parent_id: "spiffe://domain.test/node",
                spiffe_id: ("spiffe://domain.test/workload" + (. | tostring)),
                selectors: [
                    {
                        type: "unix",
                        value: ("uid:" + (. | tostring))
                    }
                ]
            }
        )
    ]
}')

Copy link
Collaborator

Choose a reason for hiding this comment

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

if you go for this, you will need to change the verified entry

# successfully synced down the workload entry.
MAXCHECKS=30
CHECKINTERVAL=1
for ((i=1;i<=MAXCHECKS;i++)); do
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can use check-synced-entry than is doing the same

@@ -0,0 +1,9 @@
# Join Token Suite
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks like this readme is not updated?


## Description

This suite verifies that:
Copy link
Collaborator

Choose a reason for hiding this comment

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

it looks tome than we must recreate an entry with the same reused id right?
and verify it is failing as expected, or recreated once we removed the old one,
maybe you can add more scripts verify that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think that ends up being difficult to handle in the integration test because of timing. I've added some more checks to the unit tests to verify those conditions. Do you think those are enough or should I see about checking those in the integration test?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, it is going difficult to test the edge scenario within an IT

Comment on lines 12 to 16
bad-spire-agent:
image: spire-agent:latest-local
volumes:
- ./conf/bad-agent:/opt/spire/conf/agent
command: ["-config", "/opt/spire/conf/agent/agent.conf"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

why it is required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its not, just some leftovers from the test I started from. I thought I cleaned those up, but turns out i didn't

@sorindumitru sorindumitru force-pushed the sync-authorized-entries-fix branch from ca3db54 to 230cd6b Compare January 30, 2025 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sync authorized entries: issues with entry id reuse Exercise SyncAuthorizedEntries in integration tests
2 participants