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

Robust cgroup path parsing of docker container ID #1605

Merged

Conversation

azdagron
Copy link
Member

@azdagron azdagron commented Jun 1, 2020

Affected functionality

Changes the default docker container ID parsing behavior. Current default behavior parses cgroup paths that look like /docker/<containerid>. This however does not work in general and the existing (undocumented) options are inflexible enough to handle cgroup paths like those generated by RHEL.

@vbotez prepared a targeted fix with #1522 (thank you!!). It opened up a discussion of the desired semantics, which ended up being quite the departure for the direction the PR started with. This PR
summarizes the functionality we landed with during that discussion.

Description of change

  • Uses a simple regex to extract the 64 hex character container ID from any cgroup path with a "docker" whole word prefix somewhere before the ID.
  • Replaces the default finder with the above regex
  • Still supports the legacy and pattern-based finders
  • Does a light refactoring to clean up the mixture of the legacy and pattern based mechanisms and to present one unified "finder" pattern.

Which issue this PR fixes
Fixes #1518

Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

Thanks @azdagron, it looks great!
I have a couple of small suggestions.

// The "finder" found a container ID, but it was blank. This is a
// defensive measure against bad matcher patterns and shouldn't
// be possible with the default finder.
return "", fmt.Errorf("workloadattestor/docker: a pattern matched, but no container id was found")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return "", fmt.Errorf("workloadattestor/docker: a pattern matched, but no container id was found")
return "", errors.New("workloadattestor/docker: a pattern matched, but no container id was found")


type defaultContainerIDFinder struct{}

func (f *defaultContainerIDFinder) FindContainerID(cgroupPath string) (string, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that a small comment about this function would be good. We can point that dockerCGroupRE is used here and it would be good to explain the meaning of an empty string result and the boolean returned.

amartinezfayo
amartinezfayo previously approved these changes Jun 2, 2020
Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

LGTM!

- Uses a simple regex to extract the 64 hex character container ID from
any cgroup path with a "docker" whole word prefix somewhere before the
ID.
- Replaces the default finder with the above regex
- Still supports the legacy and pattern-based finders

Signed-off-by: Andrew Harding <andrew.harding@hpe.com>
@azdagron azdagron force-pushed the docker-attestor-container-id-parsing branch from 2e556c6 to a185db6 Compare June 3, 2020 15:26
@azdagron
Copy link
Member Author

azdagron commented Jun 3, 2020

Fixed a misspelling in a comment to pass the linter and squashed the commits.

@azdagron azdagron merged commit 6cfef45 into spiffe:master Jun 3, 2020
@azdagron azdagron deleted the docker-attestor-container-id-parsing branch June 3, 2020 15:58
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.

Docker WorkloadAttestor plugin does not work for RHEL
2 participants