Skip to content

Commit

Permalink
WIP wiring in app-registry
Browse files Browse the repository at this point in the history
  • Loading branch information
suprjinx committed Sep 10, 2024
1 parent 902fee0 commit 0ffc7bb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
8 changes: 4 additions & 4 deletions app/interactors/refresh_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ def call
domain_info = Services::DomainOwnershipService.new.get_domain_info(context.request.fqdn)
domain_record = Domain.first_or_create(fqdn: context.request.fqdn)

if !domain_info || domain_info["isDeleted"]
if !domain_info
domain_record.delete
return
end

domain_record.update!(
group_delegation: domain_info["ownerDelegatedRequestsToTeam"],
groups: domain_info["autoApprovedGroups"],
users: domain_info["autoApprovedServiceAccounts"]
group_delegation: domain_info.group_delegation,
groups: domain_info.groups,
users: domain_info.users
)
rescue => e
Rails.logger.warn("Continuing after error in #{self.class.name}: #{e.class.name}: #{e.message}")
Expand Down
2 changes: 1 addition & 1 deletion app/lib/services/auth_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def authorize!(identity, cert_issue_req)

def decode(token)
# Decode a JWT access token using the configured base.
body = JWT.decode(token, Rails.application.config.astral[:jwt_signing_key])[0]
body = JWT.decode(token, Rails.application.configuration.astral[:jwt_signing_key])[0]
Identity.new(body)
rescue => e
Rails.logger.warn "Unable to decode token: #{e}"
Expand Down
20 changes: 20 additions & 0 deletions app/lib/services/domain_ownership_service.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
module Services
class DomainOwnershipService
attr_reader :client

def initialize
@client = Faraday.new(url: Rails.configuration.astral[:app_registry_uri]) do |faraday|
faraday.response :raise_error, include_request: true
end
end

def get_domain_info
end

private

def convert(input)
if !input || input["isDeleted"]
return nil
end

OpenStruct.new(
fqdn: domain_info["fullyQualifiedDomainName"],
group_delegation: domain_info["ownerDelegatedRequestsToTeam"],
groups: domain_info["autoApprovedGroups"],
users: domain_info["autoApprovedServiceAccounts"]
)
end
end
end
6 changes: 3 additions & 3 deletions app/lib/services/vault_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ class VaultService
def initialize
# TODO create a new token for use in the session
@client = Vault::Client.new(
address: Rails.application.config.astral[:vault_addr],
token: Rails.application.config.astral[:vault_token]
address: Rails.application.configuration.astral[:vault_addr],
token: Rails.application.configuration.astral[:vault_token]
)
end

def issue_cert(cert_issue_request)
opts = cert_issue_request.attributes
# Generate the TLS certificate using the intermediate CA
tls_cert = @client.logical.write(Rails.application.config.astral[:vault_cert_path], opts)
tls_cert = @client.logical.write(Rails.application.configuration.astral[:vault_cert_path], opts)
OpenStruct.new tls_cert.data
end
end
Expand Down
2 changes: 2 additions & 0 deletions config/astral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ shared:
vault_cert_path: "pki_int/issue/learn"
jwt_signing_key: <%= ENV["JWT_SIGNING_KEY"] %>
cert_ttl: <%= ENV["CERT_TTL"] %>
app_registry_addr: <%= ENV["APP_REGISTRY_ADDR"] %>
app_registry_token: <%= ENV["APP_REGISTRY_TOKEN"] %>

test:
cert_ttl: <%= 24.hours.in_seconds %>
Expand Down
3 changes: 1 addition & 2 deletions db/migrate/20240904175652_create_domains.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
class CreateDomains < ActiveRecord::Migration[7.2]
def change
create_table :domains do |t|
t.string :fqdn, null: false
t.string :fqdn, null: false, index: { unique: true }
t.text :users
t.text :groups
t.boolean :group_delegation, default: false
t.timestamps
t.index :fqdn, unique: true
end
end
end

0 comments on commit 0ffc7bb

Please sign in to comment.