-
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.
* Add `groups` attribute to secrets request, which are granted read-only policy on the KV
- Loading branch information
Showing
38 changed files
with
624 additions
and
169 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
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
module Clients | ||
class Vault | ||
module Identity | ||
def put_entity(name, policies) | ||
write_identity(path: "identity/entity", | ||
name: name, | ||
policies: policies, | ||
extra_params: [ :metadata, :disabled ]) | ||
end | ||
|
||
def put_group(name, policies) | ||
write_identity(path: "identity/group", | ||
name: name, | ||
policies: policies, | ||
extra_params: [ :metadata, :type, :member_group_ids, :member_entity_ids ], | ||
defaults: { type: "external" }) | ||
end | ||
|
||
def read_entity(name) | ||
client.logical.read("identity/entity/name/#{name}") | ||
end | ||
|
||
def delete_entity(name) | ||
client.logical.delete("identity/entity/name/#{name}") | ||
end | ||
|
||
def get_entity_data(name) | ||
get_identity_data("identity/entity/name/#{name}") | ||
end | ||
|
||
def read_group(name) | ||
client.logical.read("identity/group/name/#{name}") | ||
end | ||
|
||
def get_group_data(name) | ||
get_identity_data("identity/group/name/#{name}") | ||
end | ||
|
||
private | ||
|
||
def write_identity(path:, name:, policies:, defaults: {}, extra_params: [], merge_policies: true) | ||
full_path = "#{path}/name/#{name}" | ||
Domain.with_advisory_lock(full_path) do | ||
identity = client.logical.read(full_path) | ||
policies = (policies || []) + (identity&.data&.fetch(:policies) || []) if merge_policies | ||
params = defaults. | ||
merge({ | ||
name: name, | ||
policies: policies.uniq | ||
}). | ||
merge((identity&.data || {}). | ||
slice(*extra_params)). | ||
compact | ||
# cannot supply member ids for external group | ||
if params[:type] == "external" | ||
params.delete(:member_entity_ids) | ||
end | ||
client.logical.write(path, params) | ||
end | ||
end | ||
|
||
def get_identity_data(path) | ||
identity = client.logical.read(path) | ||
if identity | ||
[ identity.data[:policies], identity.data[:metadata] ] | ||
else | ||
[ [], {} ] | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module Clients | ||
class Vault | ||
module IdentityAlias | ||
def put_entity_alias(entity_name, alias_name, auth_path) | ||
write_identity_alias("entity", entity_name, alias_name, auth_path) | ||
end | ||
|
||
def put_group_alias(group_name, alias_name, auth_path) | ||
write_identity_alias("group", group_name, alias_name, auth_path) | ||
end | ||
|
||
def read_entity_alias(entity_name, alias_name, auth_path) | ||
read_identity_alias("entity", entity_name, alias_name, auth_path) | ||
end | ||
|
||
def read_group_alias(group_name, alias_name, auth_path) | ||
read_identity_alias("group", group_name, alias_name, auth_path) | ||
end | ||
|
||
def delete_entity_alias(entity_name, alias_name, auth_path) | ||
identity = client.logical.read("identity/entity/name/#{entity_name}") | ||
if identity.nil? | ||
raise "no such #{type} #{identity_name}" | ||
end | ||
id = find_identity_alias_id(identity, alias_name, auth_path) | ||
if id.nil? | ||
raise "no such alias #{alias_name}" | ||
end | ||
client.logical.delete("identity/entity-alias/id/#{id}") | ||
end | ||
|
||
private | ||
|
||
def find_identity_alias_id(identity, alias_name, auth_path) | ||
aliases = identity.data[:aliases] || [ identity.data[:alias] ] | ||
a = find_alias(aliases, alias_name, auth_path) | ||
a&.fetch(:id) | ||
end | ||
|
||
def find_alias(aliases, name, auth_path) | ||
aliases&.find { |a| a[:name] == name && a[:mount_path] == "auth/#{auth_path}/" } | ||
end | ||
|
||
def read_identity_alias(type, identity_name, alias_name, auth_path) | ||
identity = client.logical.read("identity/#{type}/name/#{identity_name}") | ||
if identity.nil? | ||
raise "no such #{type} #{identity_name}" | ||
end | ||
id = find_identity_alias_id(identity, alias_name, auth_path) | ||
if id.nil? | ||
raise "no such alias #{alias_name}" | ||
end | ||
client.logical.read("identity/#{type}-alias/id/#{id}") | ||
end | ||
|
||
def write_identity_alias(type, identity_name, alias_name, auth_path) | ||
auth_sym = "#{auth_path}/".to_sym | ||
accessor = client.logical.read("/sys/auth") | ||
accessor = accessor.data[auth_sym][:accessor] | ||
|
||
identity = client.logical.read("identity/#{type}/name/#{identity_name}") | ||
if identity.nil? | ||
raise "no such #{type} #{identity_name}" | ||
end | ||
aliases = (identity.data[:aliases] || [ identity.data[:alias] ]) | ||
identity_alias = find_alias(aliases, alias_name, auth_path) | ||
# only create alias when not existant | ||
unless identity_alias | ||
client.logical.write("identity/#{type}-alias", | ||
{ | ||
name: alias_name, | ||
mount_accessor: accessor, | ||
canonical_id: identity.data[:id] | ||
} | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.