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

feat: support secret fetching in authz-keycloak #10291

Closed

Conversation

Revolyssup
Copy link
Contributor

@Revolyssup Revolyssup commented Oct 5, 2023

Description

Currently $secret uri cannot be used in authz-keycloak plugin. This PR adds support for it.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

Signed-off-by: Ashish Tiwari <ashishjaitiwari15112000@gmail.com>
apisix/plugins/authz-keycloak.lua Outdated Show resolved Hide resolved
t/plugin/authz-keycloak.t Outdated Show resolved Hide resolved
t/plugin/authz-keycloak.t Outdated Show resolved Hide resolved
@monkeyDluffy6017
Copy link
Contributor

Please make the ci pass

@monkeyDluffy6017 monkeyDluffy6017 added the wait for update wait for the author's response in this issue/PR label Oct 7, 2023
Signed-off-by: Ashish Tiwari <ashishjaitiwari15112000@gmail.com>
Signed-off-by: Ashish Tiwari <ashishjaitiwari15112000@gmail.com>
@Revolyssup Revolyssup self-assigned this Oct 8, 2023
@Revolyssup
Copy link
Contributor Author

Please make the ci pass

done

@Revolyssup Revolyssup removed wait for update wait for the author's response in this issue/PR user responded labels Oct 9, 2023
@@ -16,11 +16,13 @@
--
local core = require("apisix.core")
local http = require "resty.http"
local secret = require("apisix.secret")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure but importing just fetch_secrets() (instead of the whole module) might be more efficient. cc: @monkeyDluffy6017

Copy link
Contributor

Choose a reason for hiding this comment

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

@Revolyssup please check this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Co-authored-by: Abhishek Choudhary <shreemaan.abhishek@gmail.com>
@Sn0rt
Copy link
Contributor

Sn0rt commented Oct 12, 2023

pls add user document for guide

@monkeyDluffy6017 monkeyDluffy6017 added the wait for update wait for the author's response in this issue/PR label Oct 12, 2023
Signed-off-by: Ashish Tiwari <ashishjaitiwari15112000@gmail.com>
@Revolyssup
Copy link
Contributor Author

pls add user document for guide

Updated the auth-keycloak plugin doc

@Revolyssup Revolyssup removed the wait for update wait for the author's response in this issue/PR label Oct 12, 2023
@@ -48,7 +48,7 @@ Refer to [Authorization Services Guide](https://www.keycloak.org/docs/latest/aut
| token_endpoint | string | False | | https://host.domain/auth/realms/foo/protocol/openid-connect/token | An OAuth2-compliant token endpoint that supports the `urn:ietf:params:oauth:grant-type:uma-ticket` grant type. If provided, overrides the value from discovery. |
| resource_registration_endpoint | string | False | | https://host.domain/auth/realms/foo/authz/protection/resource_set | A UMA-compliant resource registration endpoint. If provided, overrides the value from discovery. |
| client_id | string | True | | | The identifier of the resource server to which the client is seeking access. |
| client_secret | string | False | | | The client secret, if required. |
| client_secret | string | False | | | The client secret, if required. You can use APISIX secret to store and reference this value. APISIX currently supports storing secrets in two ways. [Environment Variables](#use-environment-variables-to-manage-secrets) and [HashiCorp Vault](#use-vault-to-manage-secrets) |
Copy link
Contributor

Choose a reason for hiding this comment

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

The links are wrong. And please add an example as well.

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 fixed the doc link. Though the lint points to the secret page which has the example in detail. So I think it will be redundant to add it again here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this PR introduce support to use env vars for accessing secrets? If yes, please add tests as well.

Regarding the docs, it would be nice to have an example like this:

(existing example that uses hard-coded value for secrets)

You can also set secrets using the secret resource to avoid having sensitive information in plain text <-- add this line

(add a basic configuration here)

See (add link to secrets.md documentation) for more information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shreemaan-abhishek Though secret is the APISIX abstraction. Behind it can be vault or env variable or anything. So I thought just testing with any one of them should work. Okay I will add tests for env variable as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay i will modify the test case

@monkeyDluffy6017 monkeyDluffy6017 added the wait for update wait for the author's response in this issue/PR label Oct 13, 2023
Signed-off-by: Ashish Tiwari <ashishjaitiwari15112000@gmail.com>
@Sn0rt
Copy link
Contributor

Sn0rt commented Oct 16, 2023

Please take a look at this case, I think it might be better understood if you can directly check the value after reslove.

ngx.say(res.value.plugins["authz-keycloak"].client_secret)

Signed-off-by: Ashish Tiwari <ashishjaitiwari15112000@gmail.com>
Signed-off-by: Ashish Tiwari <ashishjaitiwari15112000@gmail.com>
=== TEST 2: set client_secret as a reference to secret
--- yaml_config
apisix:
data_encryption:
Copy link
Contributor

Choose a reason for hiding this comment

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

why need this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the test case whose configuration I picked also had this so I copy pasted. Should I remove it?

@Revolyssup
Copy link
Contributor Author

Please take a look at this case, I think it might be better understood if you can directly check the value after reslove.

ngx.say(res.value.plugins["authz-keycloak"].client_secret)

@Sn0rt This variable extracts the exact string which is not a resolved secret. So the value of this will be $secret://...something. Here accessing this field doesn't give the resolved secret. So I am reverting back to previous test.

Signed-off-by: Ashish Tiwari <ashishjaitiwari15112000@gmail.com>
Signed-off-by: Ashish Tiwari <ashishjaitiwari15112000@gmail.com>
@Revolyssup
Copy link
Contributor Author

Revolyssup commented Oct 17, 2023

Closing this PR. Recreating this with clean commits.

@Revolyssup Revolyssup closed this Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user responded wait for update wait for the author's response in this issue/PR
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants