Skip to content

Add bearer token API keys and move authentication credentials into PerRPCCredentials#169

Merged
tminusplus merged 4 commits intorelease/apikeysfrom
tszucs/apikeys
Apr 17, 2023
Merged

Add bearer token API keys and move authentication credentials into PerRPCCredentials#169
tminusplus merged 4 commits intorelease/apikeysfrom
tszucs/apikeys

Conversation

@tminusplus
Copy link
Copy Markdown
Contributor

@tminusplus tminusplus commented Apr 17, 2023

What was changed

This PR achieves several things:

  1. Adds support for bearer token API keys in the format of$prefix_$id_$secret.
  2. Moves all authentication credentials into PerRPCCredentials to help prevent accidental leakage of secrets in code and to enforce secure connections when they are used.
  3. Refactors the GetServerConnection tests from running a urfave app to setting up a cli.Context which parses flags and then connects to a server via bufconn.
  4. Adds an --insecure flag, hidden to discourage use, to allow sending authentication over insecure connections. This is important for users who are using proxies like envoy which then sets up a secure connection from localhost.

Why?

To add support, and tests, for our beta API keys in a way which encourages secure usage by default.

Checklist

N/A

Test Plan

  • Added tests for oauth, apikeys, and HMAC.
  • Tested a tcld command with oauth creds.
  • Tested a tcld command with apikey creds.

Since HMAC / request signatures was punted, I did not test the functionality but instead moved it over verbatim into the apikey credential to keep the refactor from being destructive.

@tminusplus tminusplus requested review from anekkanti and mattkim April 17, 2023 15:59
Comment thread app/connection.go Outdated
creds, err := newRPCCredential(c)
if err != nil {
return nil, nil, err
return []grpc.DialOption{}, nil
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this going to be confusing behavior to the user? Why did we deviate from returning an error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah that is a mistake, it should be returning the error. Will fix.

}
}

if c.enableHMAC {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this feels premature to check-in to the code base?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was previously in the codebase, so I wanted to move it along to the PerRPCCredentials so this PR wasn't destructive. Then my thought was we can remove it in a future PR when desired.

Comment thread app/credentials/oauth/oauth.go Outdated

type Credential struct {
accessToken string // keep unexported to prevent accidental leakage of the token.
insecure bool
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[Nit] I'd consider inverting the name of this since reading the code feels a bit like a double negative. requiresSecureTransport or something else?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(and yes, I guess I understand you want default to be false? Maybe then we leave it as is but rename it to allowInsecureTransport)

Copy link
Copy Markdown
Contributor Author

@tminusplus tminusplus Apr 17, 2023

Choose a reason for hiding this comment

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

Will do, I initially did it to follow curl's standard arg for this and have it follow through the code but allowInsecureTransport is nicer. Do want to keep the double negative to err on the side of ensuring the default value is to enforce a secure transport.

Comment thread app/credentials/apikey/apikey.go Outdated
ID string
secret string // secret kept private to prevent accidental access.
enableHMAC bool
insecure bool
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[Nit] rename "insecure" as the term by itself is too vague.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do!

mastermanu
mastermanu previously approved these changes Apr 17, 2023
@tminusplus tminusplus merged commit 141f97f into release/apikeys Apr 17, 2023
@tminusplus tminusplus deleted the tszucs/apikeys branch April 17, 2023 20:39
tminusplus added a commit that referenced this pull request Apr 25, 2023
…rRPCCredentials (#169)

* Add bearer token API keys and introduce PerRPCCredentials

* Rename insecure to allowInsecureTransport and fix err return

* Also rename WithInsecure to WithInsecureTransport

* Add UnimplementedRequestServiceServer to connection_test.go
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.

3 participants