-
Notifications
You must be signed in to change notification settings - Fork 4
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
Support built-in function authentication with OpenFaaS IAM. #29
Conversation
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Thank you for your contribution. unfortunately, one or more of your commits are missing the required "Signed-off-by:" statement. Signing off is part of the Developer Certificate of Origin (DCO) which is used by this project. Read the DCO and project contributing guide carefully, and amend your commits using the git CLI. Note that this does not require any cryptography, keys or special steps to be taken. 💡 Shall we fix this?This will only take a few moments. First, clone your fork and checkout this branch using the git CLI. Next, set up your real name and email address:
Finally, run one of these commands to add the "Signed-off-by" line to your commits. If you only have one commit so far then run: Check that the message has been added properly by running "git log". |
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
@@ -41,3 +50,33 @@ func (c *MemoryTokenCache) Get(key string) (*Token, bool) { | |||
|
|||
return token, ok | |||
} | |||
|
|||
// StartGC starts garbage collection of expired tokens. | |||
func (c *MemoryTokenCache) StartGC(ctx context.Context, gcInterval time.Duration) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would a user access this when they've constructed a Client and have started using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, how do you stop this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would have to start it when instantiating the cache. The context can be used to stop it.
The cache can be passed in as an option when the client is constructed.
fnTokenCache := sdk.NewMemoryTokenCache()
go fnTokenCache.StartGC(context.Background(), time.Second*10)
client := sdk.NewClientWithOpts(
gatewayUrl,
httpClient,
sdk.WithAuthentication(auth),
sdk.WithFunctionTokenCache(fnTokenCache),
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that example in the examples in the README?
How would you change the example so someone could stop the StartGC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this example is also in the README.
Instead of passing the background context in the example it can be changed to use a context that can be cancelled.
Thank you for your contribution. unfortunately, one or more of your commits are missing the required "Signed-off-by:" statement. Signing off is part of the Developer Certificate of Origin (DCO) which is used by this project. Read the DCO and project contributing guide carefully, and amend your commits using the git CLI. Note that this does not require any cryptography, keys or special steps to be taken. 💡 Shall we fix this?This will only take a few moments. First, clone your fork and checkout this branch using the git CLI. Next, set up your real name and email address:
Finally, run one of these commands to add the "Signed-off-by" line to your commits. If you only have one commit so far then run: Check that the message has been added properly by running "git log". |
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
Allow the caller to construct and configure requests as required without limitations imposed by the signature of InvokeFunction. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apprved
Description
Add support for built-in function authentication with OpenFaaS IAM to the go-sdk.
To prevent a breaking change by changing the client constructor function signature a new constructor function
NewClientWithOpts
was added.The client has a new method
InvokeFunction
that can be used to invoke OpenFaaS functions.When the
auth
argument istrue
the function invocation will be authenticated with an OpenFaaS function access token. TheInvokeFunction
method handles exchanging an ID token obtained from theFunctionTokenSource
for an OpenFaaS function access token with a single function as audience.Function access tokens are cached to prevent going through the token exchange each time a function is called.
By default the authentication provider set in
ClientAuth
is used as the function token source if it implements theTokenSource
interface. Alternatively a function token source can be explicitly set with theWithFunctionTokenSource
option during client construction.The
ExchangeIDToken
token function accepts an extra list of exchange options to configure the token exchange. Supported options areWithAudience
andWithScope
.Motivation and Context
design/approved
labelSupport built-in function authentication with OpenFaaS IAM.
How Has This Been Tested?
These changes have been used and tested E2E in the OpenFaaS CLI, pro connector sdk and dashboard.
Types of changes
Checklist:
git commit -s