Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log when using default authentication container name #1526

Merged
merged 2 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions app/domain/authentication/authn_k8s/application_identity.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Authentication
module AuthnK8s

Expand All @@ -22,6 +24,9 @@ module AuthnK8s
# validation of ValidateApplicationIdentity
class ApplicationIdentity

AUTHENTICATION_CONTAINER_NAME_ANNOTATION = "authentication-container-name"
Copy link

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

DEFAULT_AUTHENTICATION_CONTAINER_NAME = "authenticator"
Copy link

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.


def initialize(host_id:, host_annotations:, service_id:)
@host_id = host_id
@host_annotations = host_annotations
Expand All @@ -45,11 +50,21 @@ def constraints
end

def container_name
annotation_name = "authentication-container-name"
annotation_value("authn-k8s/#{@service_id}/#{annotation_name}") ||
annotation_value("authn-k8s/#{annotation_name}") ||
annotation_value("kubernetes/#{annotation_name}") ||
"authenticator"
@container_name ||= annotation_value("authn-k8s/#{@service_id}/#{AUTHENTICATION_CONTAINER_NAME_ANNOTATION}") ||
annotation_value("authn-k8s/#{AUTHENTICATION_CONTAINER_NAME_ANNOTATION}") ||
annotation_value("kubernetes/#{AUTHENTICATION_CONTAINER_NAME_ANNOTATION}") ||
default_authentication_container_name
end

def default_authentication_container_name
Copy link

Choose a reason for hiding this comment

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

Authentication::AuthnK8s::ApplicationIdentity#default_authentication_container_name doesn't depend on instance state (maybe move it to another class?)

Rails.logger.debug(
LogMessages::Authentication::ContainerNameAnnotationDefaultValue.new(
AUTHENTICATION_CONTAINER_NAME_ANNOTATION,
DEFAULT_AUTHENTICATION_CONTAINER_NAME
)
)

DEFAULT_AUTHENTICATION_CONTAINER_NAME
end

# returns true if the only constraint is on the namespace, false otherwise
Expand Down
23 changes: 14 additions & 9 deletions app/domain/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module Conjur

InsufficientPasswordComplexity = Util::TrackableErrorClass.new(
msg: "The password you have chosen does not meet the complexity requirements. " \
"Choose a password that includes: 12-128 characters, 2 uppercase letters, 2 lowercase letters, 1 digit, 1 special character",
"Choose a password that includes: 12-128 characters, 2 uppercase letters, " \
"2 lowercase letters, 1 digit, 1 special character",
code: "CONJ00046E"
)

Expand Down Expand Up @@ -57,8 +58,8 @@ module Authentication
module AuthenticatorClass

DoesntStartWithAuthn = ::Util::TrackableErrorClass.new(
msg: "'{0-authenticator-parent-name}' is not a valid authenticator parent module because it does " \
"not begin with 'Authn'",
msg: "'{0-authenticator-parent-name}' is not a valid authenticator "\
"parent module because it does not begin with 'Authn'",
code: "CONJ00038E"
)

Expand Down Expand Up @@ -155,7 +156,8 @@ module Jwt
module AuthnOidc

IdTokenFieldNotFoundOrEmpty = ::Util::TrackableErrorClass.new(
msg: "Field '{0-field-name}' not found or empty in ID token. This field is defined in the id-token-user-property variable.",
msg: "Field '{0-field-name}' not found or empty in ID token. " \
"This field is defined in the id-token-user-property variable.",
code: "CONJ00013E"
)

Expand Down Expand Up @@ -188,7 +190,8 @@ module AuthnK8s
)

ScopeNotSupported = ::Util::TrackableErrorClass.new(
msg: "Resource type '{0}' is not a supported application identity. The supported resources are '{1}'",
msg: "Resource type '{0}' is not a supported application identity. " \
"The supported resources are '{1}'",
code: "CONJ00025E"
)

Expand Down Expand Up @@ -219,7 +222,7 @@ module AuthnK8s

CommonNameDoesntMatchHost = ::Util::TrackableErrorClass.new(
msg: "Client certificate CN must match host name. Cert CN: {0}. " \
"Host name: {1}. ",
"Host name: {1}.",
code: "CONJ00031E"
)

Expand Down Expand Up @@ -283,12 +286,14 @@ module AuthnAzure
)

InvalidApplicationIdentity = ::Util::TrackableErrorClass.new(
msg: "Application identity field '{0-field-name}' does not match application identity in Azure token",
msg: "Application identity field '{0-field-name}' does not match " \
"application identity in Azure token",
code: "CONJ00049E"
)

ConstraintNotSupported = ::Util::TrackableErrorClass.new(
msg: "Constraint type '{0}' is not a supported application identity. The supported resources are '{1}'",
msg: "Constraint type '{0}' is not a supported application identity. " \
"The supported resources are '{1}'",
code: "CONJ00050E"
)

Expand All @@ -308,7 +313,7 @@ module AuthnAzure
)

InvalidProviderFieldsInXmsMirid = ::Util::TrackableErrorClass.new(
msg: "Provider fields are in invalid format in xms_mirid {1}." \
msg: "Provider fields are in invalid format in xms_mirid {1}. " \
"xms_mirid must contain the resource provider namespace, the " \
"resource type, and the resource name",
code: "CONJ00054E"
Expand Down
8 changes: 7 additions & 1 deletion app/domain/logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ module Authentication
code: "CONJ00024D"
)

ContainerNameAnnotationDefaultValue = ::Util::TrackableLogMessageClass.new(
msg: "Annotation '{0-authentication-container-annotation-name}' not found. " \
"Using default value '{1-default-authentication-container}'",
code: "CONJ00033D"
)

module Security

SecurityValidated = ::Util::TrackableLogMessageClass.new(
Expand Down Expand Up @@ -167,7 +173,7 @@ module Util
)

RateLimitedCacheLimitReached = ::Util::TrackableLogMessageClass.new(
msg: "Rate limited cache reached the '{0-limit}' limit and will not" \
msg: "Rate limited cache reached the '{0-limit}' limit and will not " \
"call target for the next '{1-seconds}' seconds",
code: "CONJ00020D"
)
Expand Down