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 http node attestor #4909

Merged
merged 56 commits into from
Aug 6, 2024
Merged

Add http node attestor #4909

merged 56 commits into from
Aug 6, 2024

Conversation

kfox1111
Copy link
Contributor

@kfox1111 kfox1111 commented Feb 23, 2024

Adds an http node attestor

Fixes: #4788

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

Copy link
Member

@evan2645 evan2645 left a comment

Choose a reason for hiding this comment

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

Thank you for this @kfox1111 and for your patience. I left a handful of high level comments/questions. I had many smaller comments that I held back, I think we're clear to move this out of draft and add tests etc whenever you have a chance

doc/plugin_agent_nodeattestor_httppop.md Outdated Show resolved Hide resolved
doc/plugin_agent_nodeattestor_httppop.md Outdated Show resolved Hide resolved
doc/plugin_server_nodeattestor_httppop.md Outdated Show resolved Hide resolved
pkg/agent/plugin/nodeattestor/httppop/httppop.go Outdated Show resolved Hide resolved
return &Challenge{Nonce: nonce}, nil
}

func CalculateResponse(challenge *Challenge) (*Response, error) {
Copy link
Member

Choose a reason for hiding this comment

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

What do you envision happening here? Since the challenge is fulfilled by out of band call back from the server, I don't think we need to send anything back on the stream?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly a copy/paste thing from other plugins that use it...

But, there does need to be a message from the agent to the server after the agent starts up the http server and hosts the token to tell the server it can now try and call it. So, there is a Response, even though its blank.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I remove the extra function or leave it for consistency with the other plugins?

@kfox1111
Copy link
Contributor Author

@evan2645 Thanks for the review and the discussion! All good things to consider. :)

Copy link

@Paul-Luciano-2003 Paul-Luciano-2003 left a comment

Choose a reason for hiding this comment

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

helllo, just saying hi.
i have to build a better domain, pitch in for team players.

Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
kfox1111 added 12 commits May 11, 2024 09:48
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
@kfox1111 kfox1111 marked this pull request as ready for review May 16, 2024 22:42
@azdagron azdagron self-assigned this Jun 4, 2024
kfox1111 added 5 commits June 24, 2024 09:03
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Path: fmt.Sprintf("/.well-known/spiffe/nodeattestor/http_challenge/%s/challenge", attestationData.AgentName),
}

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

This timeout is probably better applied by the caller. And instead of using context.Background(), it should use the context from the RPC so that it respects stream cancellation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean, the value of the timeout should be passed to the function, or the whole context.WithTimeout should be lifted out, and its resulting context passed to this function?

Copy link
Member

Choose a reason for hiding this comment

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

I mean the latter. The plugin should pass its stream context to this function. The benefit there is that if the RPC is cancelled ahead of the timeout then the plugin can fail verification immediately and return. The plugin can set the timeout on the context before passing it into this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k. I think I implemented this. but not sure if its doing the right thing with context.Background() still...

pkg/common/plugin/httpchallenge/httpchallenge.go Outdated Show resolved Hide resolved
pkg/common/plugin/httpchallenge/httpchallenge.go Outdated Show resolved Hide resolved
pkg/common/plugin/httpchallenge/httpchallenge.go Outdated Show resolved Hide resolved
pkg/common/plugin/httpchallenge/httpchallenge.go Outdated Show resolved Hide resolved
pkg/common/plugin/httpchallenge/httpchallenge_test.go Outdated Show resolved Hide resolved
u, _ := url.Parse(server.URL)
_, port, _ := net.SplitHostPort(u.Host)
oldDialContext := http.DefaultTransport.(*http.Transport).DialContext
dialContext := func(ctx context.Context, network, addr string) (net.Conn, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this special dialing? Can the hostname be "localhost" instead of "foo"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

chatted via slack about this... Maybe resolved now. Please rereview.

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
common_httpchallenge.DefaultRandReader = strings.NewReader("123456789abcdefghijklmnopqrstuvwxyz")
Copy link
Member

Choose a reason for hiding this comment

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

If possible, it's better to avoid mutating package level variables from tests. Doing so inhibits parallelizing test execution in the future.

Instead of trying to control the generated nonce, can the closure you pass in for the challenge response function update a variable that controls what is returned from the http server?

Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
kfox1111 and others added 13 commits July 19, 2024 09:51
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Co-authored-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: kfox1111 <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Copy link
Member

@azdagron azdagron left a comment

Choose a reason for hiding this comment

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

Looking great! Just the last few nits and I think we're ready to merge. Thanks for the hard work on this, @kfox1111!

doc/plugin_server_nodeattestor_http_challenge.md Outdated Show resolved Hide resolved
Path: fmt.Sprintf("/.well-known/spiffe/nodeattestor/http_challenge/%s/challenge", attestationData.AgentName),
}

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

I mean the latter. The plugin should pass its stream context to this function. The benefit there is that if the RPC is cancelled ahead of the timeout then the plugin can fail verification immediately and return. The plugin can set the timeout on the context before passing it into this function.

pkg/common/plugin/httpchallenge/httpchallenge_test.go Outdated Show resolved Hide resolved
u, _ := neturl.Parse(url)
_, port, _ := net.SplitHostPort(u.Host)
return &http.Client{
Transport: &http.Transport{
Copy link
Member

Choose a reason for hiding this comment

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

Another option here is to clone the default transport like in my other comment and then replace the dialer.

kfox1111 and others added 3 commits August 5, 2024 10:56
Co-authored-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: kfox1111 <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Copy link
Member

@azdagron azdagron left a comment

Choose a reason for hiding this comment

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

\o/

@azdagron azdagron added this to the 1.10.2 milestone Aug 6, 2024
@azdagron azdagron merged commit 5b1966b into spiffe:main Aug 6, 2024
33 checks passed
@kfox1111
Copy link
Contributor Author

kfox1111 commented Aug 6, 2024

Thanks for all the help everyone! :)

valverdethiago pushed a commit to valverdethiago/spire that referenced this pull request Aug 18, 2024
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
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.

DNS/HTTP Node Attestor
5 participants