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 auth header to logcache API requests for cf-on-k8s #2267

Merged
merged 2 commits into from
Mar 25, 2022

Conversation

matt-royal
Copy link
Member

Does this PR modify CLI v6, CLI v7, or CLI v8?

This PR modifies v8. This same behavior will need to exist in v9. How should we handle that?

Description of the Change

Set the correct Authorization header when requesting logs on a cf-on-k8s deployment. This uses the same logic for generating the header as exists in the current CLI, but refactored for reuse. The behavior is unchanged for cf-on-vms

Why Is This PR Valuable?

This PR enables future work for cf-on-k8s to support logging during push, etc.

Why Should This Be In Core?

Logging is part of core behavior and we've already made changes to support auth for cf-on-k8s in core.

Applicable Issues

cloudfoundry/korifi#370

How Urgent Is The Change?

This change is necessary to unblock logging work for cf-on-k8s.

Other Relevant Parties

@cloudfoundry/cf-k8s

matt-royal and others added 2 commits March 11, 2022 14:52
- Extract "Authorization" header logic for CFonK8s into
  api/shared/WrapForCFOnK8sAuth and refactor existing code to use this
- Move LogCache client into api/logcache to avoid a cyclic import
- Bubble out error from logcache.NewClient
- New selfcontained tests for logcache request changes

Co-authored-by: Matt Royal <[email protected]>
Co-authored-by: Dave Walter <[email protected]>
Co-authored-by: Ashwin Krishna <[email protected]>
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 16, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@matt-royal matt-royal changed the base branch from master to v8 March 16, 2022 23:46
@matt-royal matt-royal closed this Mar 16, 2022
@matt-royal matt-royal reopened this Mar 16, 2022
logCacheClient := command.NewLogCacheClient(logCacheURL, configV3, nil)
logCacheClient, err := logcache.NewClient(logCacheURL, configV3, nil, v7action2.NewDefaultKubernetesConfigGetter())
if err != nil {
panic("handle this error!")
Copy link
Member Author

@matt-royal matt-royal Mar 16, 2022

Choose a reason for hiding this comment

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

Now that creating the logcache client can yield an error, we need to handle that. The existing code also panics on error a few lines up, so we copied that pattern. We could also change this function and the caller function to return errors, and then bubble that out into the main func if you prefer.

@matt-royal
Copy link
Member Author

This PR is built on top of #2266, so that PR should be accepted first.

Comment on lines +71 to +77
if transportConfig.WrapTransport == nil {
// i.e. not auth-provider or exec plugin
return transport.HTTPWrappersForConfig(transportConfig, roundTripper)
}

// using auth provider to generate token
return transportConfig.WrapTransport(roundTripper), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

We have recently found our that this check is redundant.

Copy link
Contributor

Choose a reason for hiding this comment

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

should that check be removed before we merge the PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we might get away with just return transportConfig.HTTPWrappersForConfig(...) but I'd try it first, just in case.

Copy link
Contributor

@reedr3 reedr3 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@jdgonzaleza jdgonzaleza left a comment

Choose a reason for hiding this comment

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

LGTM

Once merged into v8, We should backport into main/master as this must be included in future cli versions 😬

@reedr3 reedr3 merged commit aad94f8 into cloudfoundry:v8 Mar 25, 2022
reedr3 added a commit that referenced this pull request Mar 25, 2022
Add auth header to logcache API requests for cf-on-k8s
@matt-royal matt-royal deleted the add-auth-to-logs branch March 25, 2022 16:58
Copy link
Member

@a-b a-b left a comment

Choose a reason for hiding this comment

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

LGTM

@a-b
Copy link
Member

a-b commented May 10, 2022

Once merged into v8, We should backport into main/master as this must be included in future cli versions 😬

It's hard for me to imagine anything in v8 that does not belong to the main (future v9) branch.

gururajsh pushed a commit that referenced this pull request May 17, 2022
Add auth header to logcache API requests for cf-on-k8s
gururajsh added a commit that referenced this pull request May 17, 2022
gururajsh added a commit that referenced this pull request May 17, 2022
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.

6 participants