-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:G-Research/astral
- Loading branch information
Showing
4 changed files
with
45 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
module Clients | ||
class Vault | ||
module EntityAlias | ||
def put_entity_alias(entity_name, alias_name, auth_method) | ||
def put_entity_alias(entity_name, alias_name, auth_path) | ||
e = read_entity(entity_name) | ||
if e.nil? | ||
raise "no such entity #{entity_name}" | ||
end | ||
canonical_id = e.data[:id] | ||
auth_sym = "#{auth_method}/".to_sym | ||
auth_sym = "#{auth_path}/".to_sym | ||
accessor = client.logical.read("/sys/auth").data[auth_sym][:accessor] | ||
client.logical.write("identity/entity-alias", | ||
name: alias_name, | ||
canonical_id: canonical_id, | ||
mount_accessor: accessor) | ||
end | ||
|
||
def read_entity_alias_id(entity_name, alias_name) | ||
def read_entity_alias_id(entity_name, alias_name, auth_path) | ||
e = read_entity(entity_name) | ||
if e.nil? | ||
raise "no such entity #{entity_name}" | ||
end | ||
aliases = e.data[:aliases] | ||
a = aliases.find { |a| a[:name] == alias_name } | ||
a = find_alias(aliases, alias_name, auth_path) | ||
if a.nil? | ||
raise "no such alias #{alias_name}" | ||
end | ||
a[:id] | ||
end | ||
|
||
def read_entity_alias(entity_name, alias_name) | ||
id = read_entity_alias_id(entity_name, alias_name) | ||
def read_entity_alias(entity_name, alias_name, auth_path) | ||
id = read_entity_alias_id(entity_name, alias_name, auth_path) | ||
client.logical.read("identity/entity-alias/id/#{id}") | ||
end | ||
|
||
def delete_entity_alias(entity_name, alias_name) | ||
id = read_entity_alias_id(entity_name, alias_name) | ||
def delete_entity_alias(entity_name, alias_name, auth_path) | ||
id = read_entity_alias_id(entity_name, alias_name, auth_path) | ||
client.logical.delete("identity/entity-alias/id/#{id}") | ||
end | ||
|
||
private | ||
def find_alias(aliases, name, auth_path) | ||
aliases.find { |a| a[:name] == name && a[:mount_path] == "auth/#{auth_path}/" } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,11 +13,16 @@ class TestCase | |
|
||
# Helper methods | ||
def jwt_authorized | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqb2huLmRvZUBleGFtcGxlLmNvbSIsIm5hbWUiOiJKb2huIERvZSIsImlhdCI6MTUxNjIzOTAyMiwiZ3JvdXBzIjpbImdyb3VwMSIsImdyb3VwMiJdLCJhdWQiOiJhc3RyYWwifQ.tfRLXmE_eq-piP88_clwPWrYfMAQbCJAeZQI6OFxZSI" | ||
@@authorized_token ||= JWT.encode(@@authorized_data, Config[:jwt_signing_key]) | ||
end | ||
|
||
def jwt_unauthorized | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhcHBsaWNhdGlvbl9uYW1lIiwiY29tbW9uX25hbWUiOiJleGFtcGxlLmNvbSIsImlwX3NhbnMiOiIxMC4wLjEuMTAwIn0.gEUyaZcARiBQNq2RUwZU0MdFXqthyo_oSQ8DAgKvxCs" | ||
@@unauthorized_token ||= JWT.encode(@@unauthorized_data, "bad_secret") | ||
end | ||
|
||
private | ||
@@authorized_data = { "sub"=>"[email protected]", "name"=>"John Doe", "iat"=>1516239022, | ||
"groups"=>[ "group1", "group2" ], "aud"=>"astral" } | ||
@@unauthorized_data = { "sub"=>"application_name", "common_name"=>"example.com", "ip_sans"=>"10.0.1.100" } | ||
end | ||
end |