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

OIDC support #144

Merged
merged 1 commit into from
Dec 19, 2022
Merged

OIDC support #144

merged 1 commit into from
Dec 19, 2022

Conversation

szh
Copy link
Contributor

@szh szh commented Dec 9, 2022

Desired Outcome

Add support for authn-oidc in the Conjur Golang API

Implemented Changes

  • Support the List OIDC Providers endpoint (Docs)
  • Support the OIDC authentication (V2) endpoint (Docs)

Connected Issue/Story

CyberArk internal issue ID: ONYX-25484

Changelog

  • The CHANGELOG has been updated, or
  • This PR does not include user-facing changes and doesn't require a
    CHANGELOG update

Test coverage

  • This PR includes new unit and integration tests to go with the code
    changes, or
  • The changes in this PR do not require tests

Documentation

  • Docs (e.g. READMEs) were updated in this PR
  • A follow-up issue to update official docs has been filed here: [insert issue ID]
  • This PR does not require updating any documentation

Behavior

  • This PR changes product behavior and has been reviewed by a PO, or
  • These changes are part of a larger initiative that will be reviewed later, or
  • No behavior was changed with this PR

Security

  • Security architect has reviewed the changes in this PR,
  • These changes are part of a larger initiative with a separate security review, or
  • There are no security aspects to these changes

@szh szh requested a review from a team as a code owner December 9, 2022 13:53
@szh szh self-assigned this Dec 9, 2022
@szh szh mentioned this pull request Dec 12, 2022
13 tasks
@szh szh force-pushed the oidc branch 5 times, most recently from da2c77b to 52563e2 Compare December 13, 2022 20:34
CHANGELOG.md Show resolved Hide resolved
"github.com/cyberark/conjur-api-go/conjurapi/response"
)

// OidcProviderResponse contains information about an OIDC provider.
type OidcProviderResponse struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if there is a way to construct a provider information response without filtering it through a hard-coded struct.

Thinking about a case where the /providers endpoint needs to update its response content - this OidcProviderResponse struct would need to be kept in phase. If we used a generic string-to-string hashmap instead, maybe we could avoid all that, and decouple the Go API's response from the contained data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point, but I think there's utility in having a struct, particularly so the CLI (or other API consumers) can know what fields to expect. I'll also point out that we do something similar in PolicyResponse.

conjurapi/client.go Outdated Show resolved Hide resolved
conjurapi/authn.go Outdated Show resolved Hide resolved
Comment on lines 154 to 156
if err == nil {
c.cacheOidcToken(resp)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I might be missing the forest for the trees, but this doesn't seem specific to the API project, and instead could be the responsibility of the consuming client.

I can imagine a Go client that chooses to store the access token elsewhere (like Conjur UI, which uses an encrypted session cookie) and doesn't want/need the token saved to file elsewhere.

Copy link
Contributor Author

@szh szh Dec 15, 2022

Choose a reason for hiding this comment

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

So this is complicated. @doodlesbykumbi and I have been discussing whether the netrc storage should happen in the CLI or API. See this comment:

// TODO: Perhaps .netrc storage should be moved to the conjur-api-go repository. At that point we could store
// the access token there as we do with the API key.

In the meantime, the practical reason I took this approach is that the CLI doesn't have access to the access token - it stays in the API library, and I didn't think it was such a great idea to change that. I'm open to more discussion though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, I'm definitely remembering this topic now.

I'm concerned that if a user is only dealing with the API's public interface, they'll notice the OidcAuthenticate function returns an access token, and the token being written to a file could be either unintended or invisible.

Or maybe I'm thinking about this the wrong way, and the API is using the cached token to authenticate HTTP calls, so what is really "unintended" is returning the access token to a user at all!

Maybe this means that returning an access token and caching one should be two distinct function calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an interesting point. In truth, we could make the Authenticate() and OidcAuthenticate() methods private, as far as the CLI is concerned. I suppose the issue then would be for clients that want to use the API in a different way.
Maybe the best solution would be to make a separate function for caching the token, but I would argue that by calling OidcAuthenticate() instead of Authenticate() it's implicit that this flow (including caching) should be used. OIDC generally can't be used for automation as the whole advantage it has over regular authn is that it requires a second factor, ie user interaction.

@szh szh force-pushed the oidc branch 2 times, most recently from e678fa2 to 94a0f99 Compare December 15, 2022 14:47
@john-odonnell
Copy link
Contributor

Thanks for the comments, LGTM! Just needs a rebase and I'll happily approve 😄

Copy link
Contributor

@john-odonnell john-odonnell left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@szh szh merged commit 505f04b into main Dec 19, 2022
@szh szh deleted the oidc branch December 19, 2022 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants