This repository has been archived by the owner on May 1, 2020. It is now read-only.
/
authentication.go
143 lines (123 loc) · 6.36 KB
/
authentication.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright (C) 2018 Synopsys, Inc.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package containers
import (
horizonapi "github.com/blackducksoftware/horizon/pkg/api"
"github.com/blackducksoftware/horizon/pkg/components"
"github.com/blackducksoftware/synopsys-operator/pkg/util"
)
// GetAuthenticationDeployment will return the authentication deployment
func (c *Creater) GetAuthenticationDeployment(imageName string) (*components.Deployment, error) {
volumeMounts := c.getAuthenticationVolumeMounts()
var authEnvs []*horizonapi.EnvConfig
authEnvs = append(authEnvs, c.getHubDBConfigEnv())
authEnvs = append(authEnvs, c.getHubConfigEnv())
authEnvs = append(authEnvs, &horizonapi.EnvConfig{Type: horizonapi.EnvVal, NameOrPrefix: "HUB_MAX_MEMORY", KeyOrVal: c.hubContainerFlavor.AuthenticationHubMaxMemory})
hubAuthContainerConfig := &util.Container{
ContainerConfig: &horizonapi.ContainerConfig{Name: "authentication", Image: imageName,
PullPolicy: horizonapi.PullAlways, MinMem: c.hubContainerFlavor.AuthenticationMemoryLimit, MaxMem: c.hubContainerFlavor.AuthenticationMemoryLimit, MinCPU: "", MaxCPU: ""},
EnvConfigs: authEnvs,
VolumeMounts: volumeMounts,
PortConfig: []*horizonapi.PortConfig{{ContainerPort: authenticationPort, Protocol: horizonapi.ProtocolTCP}},
}
if c.blackDuck.Spec.LivenessProbes {
hubAuthContainerConfig.LivenessProbeConfigs = []*horizonapi.ProbeConfig{{
ActionConfig: horizonapi.ActionConfig{
Type: horizonapi.ActionTypeCommand,
Command: []string{
"/usr/local/bin/docker-healthcheck.sh",
"https://127.0.0.1:8443/api/health-checks/liveness",
"/opt/blackduck/hub/hub-authentication/security/root.crt",
"/opt/blackduck/hub/hub-authentication/security/blackduck_system.crt",
"/opt/blackduck/hub/hub-authentication/security/blackduck_system.key",
},
},
Delay: 240,
Interval: 30,
Timeout: 10,
MinCountFailure: 10,
}}
}
podConfig := &util.PodConfig{
Volumes: c.getAuthenticationVolumes(),
Containers: []*util.Container{hubAuthContainerConfig},
Labels: c.GetVersionLabel("authentication"),
NodeAffinityConfigs: c.GetNodeAffinityConfigs("authentication"),
}
if c.blackDuck.Spec.RegistryConfiguration != nil && len(c.blackDuck.Spec.RegistryConfiguration.PullSecrets) > 0 {
podConfig.ImagePullSecrets = c.blackDuck.Spec.RegistryConfiguration.PullSecrets
}
if !c.config.IsOpenshift {
podConfig.FSGID = util.IntToInt64(0)
}
return util.CreateDeploymentFromContainer(
&horizonapi.DeploymentConfig{Namespace: c.blackDuck.Spec.Namespace, Name: util.GetResourceName(c.blackDuck.Name, util.BlackDuckName, "authentication"), Replicas: util.IntToInt32(1)},
podConfig, c.GetLabel("authentication"))
}
// getAuthenticationVolumes will return the authentication volumes
func (c *Creater) getAuthenticationVolumes() []*components.Volume {
hubAuthSecurityEmptyDir, _ := util.CreateEmptyDirVolumeWithoutSizeLimit("dir-authentication-security")
var hubAuthVolume *components.Volume
if c.blackDuck.Spec.PersistentStorage {
hubAuthVolume, _ = util.CreatePersistentVolumeClaimVolume("dir-authentication", c.getPVCName("authentication"))
} else {
hubAuthVolume, _ = util.CreateEmptyDirVolumeWithoutSizeLimit("dir-authentication")
}
volumes := []*components.Volume{hubAuthVolume, c.getDBSecretVolume(), hubAuthSecurityEmptyDir}
// Mount the HTTPS proxy certificate if provided
if len(c.blackDuck.Spec.ProxyCertificate) > 0 {
volumes = append(volumes, c.getProxyVolume())
}
// Custom CA auth
if len(c.blackDuck.Spec.AuthCustomCA) > 1 {
authCustomCaVolume, _ := util.CreateSecretVolume("auth-custom-ca", util.GetResourceName(c.blackDuck.Name, util.BlackDuckName, "auth-custom-ca"), 0444)
volumes = append(volumes, authCustomCaVolume)
}
return volumes
}
// getAuthenticationVolumeMounts will return the authentication volume mounts
func (c *Creater) getAuthenticationVolumeMounts() []*horizonapi.VolumeMountConfig {
volumesMounts := []*horizonapi.VolumeMountConfig{
{Name: "db-passwords", MountPath: "/tmp/secrets/HUB_POSTGRES_ADMIN_PASSWORD_FILE", SubPath: "HUB_POSTGRES_ADMIN_PASSWORD_FILE"},
{Name: "db-passwords", MountPath: "/tmp/secrets/HUB_POSTGRES_USER_PASSWORD_FILE", SubPath: "HUB_POSTGRES_USER_PASSWORD_FILE"},
{Name: "dir-authentication", MountPath: "/opt/blackduck/hub/hub-authentication/ldap"},
{Name: "dir-authentication-security", MountPath: "/opt/blackduck/hub/hub-authentication/security"},
}
// Mount the HTTPS proxy certificate if provided
if len(c.blackDuck.Spec.ProxyCertificate) > 0 {
volumesMounts = append(volumesMounts, &horizonapi.VolumeMountConfig{
Name: "proxy-certificate",
MountPath: "/tmp/secrets/HUB_PROXY_CERT_FILE",
SubPath: "HUB_PROXY_CERT_FILE",
})
}
if len(c.blackDuck.Spec.AuthCustomCA) > 1 {
volumesMounts = append(volumesMounts, &horizonapi.VolumeMountConfig{
Name: "auth-custom-ca",
MountPath: "/tmp/secrets/AUTH_CUSTOM_CA",
SubPath: "AUTH_CUSTOM_CA",
})
}
return volumesMounts
}
// GetAuthenticationService will return the authentication service
func (c *Creater) GetAuthenticationService() *components.Service {
return util.CreateService("authentication", c.GetLabel("authentication"), c.blackDuck.Spec.Namespace, authenticationPort, authenticationPort, horizonapi.ServiceTypeServiceIP, c.GetVersionLabel("authentication"))
// TODO: remove GetResourceName method until the HUB-20482 is fixed. once it if fixed, add them back
// return util.CreateService(util.GetResourceName(c.blackDuck.Name, util.BlackDuckName, "authentication"), c.GetLabel("authentication"), c.blackDuck.Spec.Namespace, authenticationPort, authenticationPort, horizonapi.ServiceTypeServiceIP, c.GetVersionLabel("authentication"))
}