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(admin): add kms admin api #8394

Merged
merged 17 commits into from
Nov 29, 2022
Merged

Conversation

kingluo
Copy link
Contributor

@kingluo kingluo commented Nov 24, 2022

Description

As part of #8319:

Support adding KMS resources through Admin API.

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)

apisix/schema_def.lua Outdated Show resolved Hide resolved
apisix/schema_def.lua Outdated Show resolved Hide resolved
t/admin/kms.t Outdated
$block->set_value("request", "GET /t");
}

if ((!defined $block->error_log) && (!defined $block->no_error_log)) {
Copy link
Member

Choose a reason for hiding this comment

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

We don't need this now?



function _M.delete(id, conf, sub_path)
local uri_segs = core.utils.split_uri(sub_path)
Copy link
Member

Choose a reason for hiding this comment

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

Can we refactor the code to get type & id from sub_path in a function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PATCH requires a different number of segments than GET and PUT, then it makes function wrap a bit complicated.
And the goal is to replace id with real id, and the original id is actually kms type, which is different from other admin resources. And the replacement happens after the invocation, so I think it's trivial to wrap them into function.

Copy link
Member

Choose a reason for hiding this comment

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

But we can share the same code for GET and PUT and DELETE right? This is enough to simplify the implementation instead of copying the code three times.


local res, err = core.etcd.atomic_set(key, node_value, nil, modified_index)
if not res then
core.log.error("failed to set new consumer group[", key, "]: ", err)
Copy link
Member

Choose a reason for hiding this comment

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

Typo?

function _M.put(id, conf, sub_path)
local uri_segs = core.utils.split_uri(sub_path)
if #uri_segs ~= 1 then
return 400, "no kms id in uri"
Copy link
Member

Choose a reason for hiding this comment

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

Better to keep the style of error message. We should use {error_msg = xxx} like other places

@kingluo kingluo marked this pull request as draft November 25, 2022 09:37
apisix/constants.lua Outdated Show resolved Hide resolved
t/admin/kms.t Show resolved Hide resolved
@soulbird soulbird marked this pull request as ready for review November 28, 2022 09:42
Copy link
Member

@spacewander spacewander left a comment

Choose a reason for hiding this comment

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

Need to address #8394 (comment) first

apisix/admin/kms.lua Outdated Show resolved Hide resolved
apisix/admin/kms.lua Outdated Show resolved Hide resolved
docs/en/latest/admin-api.md Show resolved Hide resolved
| prefix | True | string | key prefix
| token | True | string | vault token. | |
| desc | False | Auxiliary | Description of usage scenarios. | kms xxxx |
| labels | False | Match Rules | Attributes of the kms specified as key-value pairs. | {"version":"v2","build":"16","env":"production"} |
Copy link
Member

Choose a reason for hiding this comment

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

Does kms have these fields?

| uri | True | URI | URI of the vault server. | |
| prefix | True | string | key prefix
| token | True | string | vault token. | |
| desc | False | Auxiliary | Description of usage scenarios. | kms xxxx |
Copy link
Member

Choose a reason for hiding this comment

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

The kms_vault doesn't have desc field

t/admin/kms.t Show resolved Hide resolved
@spacewander spacewander merged commit de069aa into apache:master Nov 29, 2022
hongbinhsu added a commit to fitphp/apix that referenced this pull request Dec 4, 2022
* upstream/master: (48 commits)
  fix(ai): remove BUILD_ROUTER event when ai module is unloaded (apache#8184)
  chore: add some comment for make_request_to_vault function (apache#8420)
  docs: update admin api English doc (apache#8227)
  ci: use fixed os version of ubuntu (apache#8438)
  feat: Support store secrets in secrets manager for auth plugin via kms components (apache#8421)
  feat: interact via gRPC in APISIX Admin API (apache#8411)
  fix: last_err can be nil when the reconnection is successful (apache#8377)
  feat: support global data encryption of secret information (apache#8403)
  refactor(env): rename funtion name (apache#8426)
  feat(admin): add kms admin api (apache#8394)
  docs: update consumer and upstream docs (apache#8223)
  ci: add cron job for GM (apache#8398)
  docs: add kms env doc (apache#8419)
  feat: Added log format support in syslog plugin. (apache#8279)
  feat: add vault common components (apache#8412)
  docs: update global-rule/plugin-config/plugin/ docs (apache#8262)
  docs: update consumer-group/router/service/script doc (apache#8332)
  feat: support store secret in env for auth plugin (apache#8390)
  docs: update Upgrade Guide CN version (apache#8392)
  docs: add GM plugin EN doc to make website display normally (apache#8393)
  ...
Copy link
Contributor

@shreemaan-abhishek shreemaan-abhishek left a comment

Choose a reason for hiding this comment

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

I was trying to use this method and found these difficulties. I am new to Lua so my suggestions may not be of use.

end


function _M.get(id, conf, sub_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

@kingluo, @soulbird conf is unused.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is to be consistent with the operation functions of other resources, and they will be called uniformly here https://github.com/apache/apisix/blob/master/apisix/admin/init.lua#L201
In fact, we are refactoring this part, you are welcome to participate in the review #8611

end

utils.fix_count(res.body, id)
return res.status, res.body
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about return res, nil? This way the second return variable is always of type error and first one will always be response

Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

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.

5 participants