Skip to content

feat(vault): vault lua module, integration with jwt-auth authentication plugin#5745

Merged
spacewander merged 28 commits into
apache:masterfrom
bisakhmondal:vault-jwt
Dec 15, 2021
Merged

feat(vault): vault lua module, integration with jwt-auth authentication plugin#5745
spacewander merged 28 commits into
apache:masterfrom
bisakhmondal:vault-jwt

Conversation

@bisakhmondal

@bisakhmondal bisakhmondal commented Dec 8, 2021

Copy link
Copy Markdown
Member

What this PR does / why we need it:

This PR integrates HashiCorp Vault with APISIX jwt-auth authentication plugin.
With this PR

  • APISIX can store, delete, fetch data from vault (lua module)
  • jwt-auth can retrieve private and public keys from the vault's encrypted kv storage.
  • jwt-auth can store and retrieve signing secrets into and from the vault.

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

Comment thread apisix/core/vault.lua Outdated
Comment thread apisix/plugins/jwt-auth.lua Outdated
Comment thread apisix/plugins/jwt-auth.lua Outdated
Comment thread apisix/admin/consumers.lua Outdated
Comment thread apisix/plugins/jwt-auth.lua Outdated

@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.

@bisakhmondal
Please don't ignore the suggestion from the maintainer, thanks!

Comment thread t/plugin/jwt-auth-vault.t Outdated
Comment thread docs/en/latest/plugins/jwt-auth.md Outdated
Comment thread docs/en/latest/plugins/jwt-auth.md Outdated
Comment thread docs/en/latest/plugins/jwt-auth.md Outdated
Comment thread conf/config-default.yaml Outdated
#sni: # the SNI for etcd TLS requests. If missed, the host part of the URL will be used.

# storage backend for sensitive data storage and retrieval
vault:

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.

Let's comment out this section, we do not need to require vault by default.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

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.

Err. Actually, I mean like this :

#vault:
  # ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ahh, I get it now 😄

@bisakhmondal bisakhmondal Dec 12, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated. Thanks for the review

Comment thread apisix/plugins/jwt-auth.lua Outdated
local plugin_name = "jwt-auth"
local pcall = pcall

local jwt_vault_prefix = "jwt-auth/keys/"

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.

What about changing it to consumer/<username>/jwt-auth/?
I think about it several times. Although it requires to change several places in this PR, the new format is more extendable, and easier to recognize. People will remember the username better than the key.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. Addressed

Comment thread conf/config-default.yaml Outdated
#sni: # the SNI for etcd TLS requests. If missed, the host part of the URL will be used.

# storage backend for sensitive data storage and retrieval
vault:

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.

Err. Actually, I mean like this :

#vault:
  # ...

Comment thread t/plugin/jwt-auth-vault.t Outdated
}
}
}]],
[[{

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.

Could we remove the expected response? We don't need to check this output anymore. More other tests already do it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure. Done

@spacewander

Copy link
Copy Markdown
Member

My review is almost done, only a few things need to be addressed. 😄

Comment thread t/plugin/jwt-auth-vault.t Outdated
Comment thread t/plugin/jwt-auth-vault.t Outdated


=== TEST 6: sign a HS256 jwt and access/verify /secure-endpoint
--- extra_yaml_config

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 can set up a common yaml config in this file?

Comment thread t/plugin/jwt-auth-vault.t
Comment on lines +42 to +51
my $vault_config = $block->extra_yaml_config // <<_EOC_;
vault:
host: "http://0.0.0.0:8200"
timeout: 10
prefix: kv/apisix
token: root
_EOC_

$block->set_value("extra_yaml_config", $vault_config);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

How is it now? @spacewander

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.

LGTM

Comment thread t/plugin/jwt-auth-vault.t Outdated
@spacewander
spacewander merged commit 0d4f65a into apache:master Dec 15, 2021
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