Skip to content

feat(admin): add kms admin api#8394

Merged
spacewander merged 17 commits into
apache:masterfrom
kingluo:admin_api_kms
Nov 29, 2022
Merged

feat(admin): add kms admin api#8394
spacewander merged 17 commits into
apache:masterfrom
kingluo:admin_api_kms

Conversation

@kingluo

@kingluo kingluo commented Nov 24, 2022

Copy link
Copy Markdown
Contributor

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)

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

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

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.

We don't need this now?

Comment thread apisix/admin/kms.lua Outdated


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

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.

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

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.

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
Copy Markdown
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.

Comment thread apisix/admin/kms.lua Outdated

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Typo?

Comment thread apisix/admin/kms.lua Outdated
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
Copy Markdown
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
Comment thread apisix/constants.lua Outdated
Comment thread t/admin/kms.t
@soulbird
soulbird marked this pull request as ready for review November 28, 2022 09:42

@spacewander spacewander left a comment

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.

Need to address #8394 (comment) first

Comment thread apisix/admin/kms.lua Outdated
Comment thread apisix/admin/kms.lua Outdated
Comment thread docs/en/latest/admin-api.md
Comment thread docs/en/latest/admin-api.md Outdated
| 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
Copy Markdown
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?

Comment thread docs/en/latest/admin-api.md Outdated
| 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
Copy Markdown
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

Comment thread t/admin/kms.t
@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)
  ...

@shreemaan-abhishek shreemaan-abhishek left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread apisix/admin/kms.lua
end


function _M.get(id, conf, sub_path)

Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread apisix/admin/kms.lua
end

utils.fix_count(res.body, id)
return res.status, res.body

Copy link
Copy Markdown
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
Copy Markdown
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