2020-08-21 08:10:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Kas
|
|
|
|
INTERNAL_API_REQUEST_HEADER = 'Gitlab-Kas-Api-Request'
|
2021-05-05 11:10:05 -04:00
|
|
|
VERSION_FILE = 'GITLAB_KAS_VERSION'
|
2020-08-21 08:10:22 -04:00
|
|
|
JWT_ISSUER = 'gitlab-kas'
|
2021-08-02 05:10:09 -04:00
|
|
|
K8S_PROXY_PATH = 'k8s-proxy'
|
2020-08-21 08:10:22 -04:00
|
|
|
|
|
|
|
include JwtAuthenticatable
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def verify_api_request(request_headers)
|
2022-01-06 01:10:35 -05:00
|
|
|
decode_jwt(request_headers[INTERNAL_API_REQUEST_HEADER], issuer: JWT_ISSUER)
|
2020-08-21 08:10:22 -04:00
|
|
|
rescue JWT::DecodeError
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def secret_path
|
|
|
|
Gitlab.config.gitlab_kas.secret_file
|
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_secret!
|
|
|
|
return if File.exist?(secret_path)
|
|
|
|
|
|
|
|
write_secret
|
|
|
|
end
|
2021-02-04 22:09:09 -05:00
|
|
|
|
2021-05-05 11:10:05 -04:00
|
|
|
# Return GitLab KAS version
|
|
|
|
#
|
|
|
|
# @return [String] version
|
|
|
|
def version
|
|
|
|
@_version ||= Rails.root.join(VERSION_FILE).read.chomp
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return GitLab KAS external_url
|
|
|
|
#
|
|
|
|
# @return [String] external_url
|
|
|
|
def external_url
|
|
|
|
Gitlab.config.gitlab_kas.external_url
|
|
|
|
end
|
|
|
|
|
2021-08-02 05:10:09 -04:00
|
|
|
def tunnel_url
|
2021-10-04 08:11:58 -04:00
|
|
|
configured = Gitlab.config.gitlab_kas['external_k8s_proxy_url']
|
|
|
|
return configured if configured.present?
|
|
|
|
|
|
|
|
# Legacy code path. Will be removed when all distributions provide a sane default here
|
2021-08-05 02:09:25 -04:00
|
|
|
uri = URI.join(external_url, K8S_PROXY_PATH)
|
|
|
|
uri.scheme = uri.scheme.in?(%w(grpcs wss)) ? 'https' : 'http'
|
|
|
|
uri.to_s
|
2021-08-02 05:10:09 -04:00
|
|
|
end
|
|
|
|
|
2021-06-14 23:10:34 -04:00
|
|
|
# Return GitLab KAS internal_url
|
|
|
|
#
|
|
|
|
# @return [String] internal_url
|
|
|
|
def internal_url
|
|
|
|
Gitlab.config.gitlab_kas.internal_url
|
|
|
|
end
|
|
|
|
|
2021-05-05 11:10:05 -04:00
|
|
|
# Return whether GitLab KAS is enabled
|
|
|
|
#
|
|
|
|
# @return [Boolean] external_url
|
|
|
|
def enabled?
|
|
|
|
!!Gitlab.config['gitlab_kas']&.fetch('enabled', false)
|
|
|
|
end
|
2020-08-21 08:10:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|