Skip to content

Commit

Permalink
rewrite secrets mount
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandredevely committed Mar 23, 2024
1 parent 8dd3dea commit 176d94c
Showing 1 changed file with 42 additions and 35 deletions.
77 changes: 42 additions & 35 deletions oc/od/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,40 +977,47 @@ def build_volumes_secrets( self, authinfo:AuthInfo, userinfo:AuthUser, volume_ty
# abcdesktop is the default namespace
# mount secret in /var/secrets/$NAMESPACE
#
self.logger.debug( "listing list_dict_secret_data access_type='auth'" )
mysecretdict = self.list_dict_secret_data( authinfo, userinfo, access_type='auth' )
for secret_auth_name in mysecretdict.keys():
# https://kubernetes.io/docs/concepts/configuration/secret
# create an entry eq:
# /var/secrets/abcdesktop/ntlm
# /var/secrets/abcdesktop/cntlm
# /var/secrets/abcdesktop/kerberos
#

self.logger.debug( f"checking {secret_auth_name} access_type='auth' " )
# only mount secrets_requirement
if isinstance( secrets_requirement, list ):
if secret_auth_name not in secrets_requirement:
self.logger.debug( f"{secret_auth_name} is not in {secrets_requirement}" )
self.logger.debug( f"{secret_auth_name} is skipped" )
continue

self.logger.debug( f"adding secret type {mysecretdict[secret_auth_name]['type']} to volume pod" )
secretmountPath = oc.od.settings.desktop['secretsrootdirectory'] + mysecretdict[secret_auth_name]['type']
# mode is 644 -> rw-r--r--
# Owing to JSON limitations, you must specify the mode in decimal notation.
# 644 in decimal equal to 420
volumes[secret_auth_name] = {
'name':secret_auth_name,
'secret': {
'secretName': secret_auth_name,
'defaultMode': 420
}
}
volumes_mount[secret_auth_name] = {
'name':secret_auth_name,
'mountPath':secretmountPath
}
self.logger.debug( f"secrets_requirement is {secrets_requirement}" )
if not isinstance( secrets_requirement, list ):
self.logger.debug( f"skipping secrets_requirement type={type(secrets_requirement)}, no secret to mount" )
else:
self.logger.debug( "listing list_dict_secret_data access_type='auth'" )
mysecretdict = self.list_dict_secret_data( authinfo, userinfo, access_type='auth' )
if isinstance( mysecretdict, dict):
# read all entries in dict
# {'auth-ntlm-fry': {'type': 'abcdesktop/ntlm', 'data': {...}}}
self.logger.debug(f"list of secret is {mysecretdict.keys()}")
for secret_auth_name in mysecretdict.keys():
# https://kubernetes.io/docs/concepts/configuration/secret
# create an entry eq:
#
# /var/secrets/abcdesktop/ntlm
# /var/secrets/abcdesktop/kerberos
#
self.logger.debug(f"checking {secret_auth_name} access_type='auth'")

# only mount secrets_requirement
if 'all' not in secrets_requirement:
if mysecretdict[secret_auth_name]['type'] not in secrets_requirement:
self.logger.debug(f"skipping {mysecretdict[secret_auth_name]['type']} not in {secrets_requirement}")
continue

self.logger.debug( f"adding secret type {mysecretdict[secret_auth_name]['type']} to volume pod" )
secretmountPath = oc.od.settings.desktop['secretsrootdirectory'] + mysecretdict[secret_auth_name]['type']
# mode is 644 -> rw-r--r--
# Owing to JSON limitations, you must specify the mode in decimal notation.
# 644 in decimal equal to 420
volumes[secret_auth_name] = {
'name':secret_auth_name,
'secret': {
'secretName': secret_auth_name,
'defaultMode': 420
}
}
volumes_mount[secret_auth_name] = {
'name':secret_auth_name,
'mountPath':secretmountPath
}
return (volumes, volumes_mount)

def build_volumes_additional_by_rules( self, authinfo, userinfo, volume_type, secrets_requirement, rules={}, **kwargs):
Expand Down Expand Up @@ -3164,7 +3171,7 @@ def createdesktop(self, authinfo:AuthInfo, userinfo:AuthUser, **kwargs)-> ODDesk
kwargs['shareProcessMemory'] = shareProcessMemory

# all volumes and secrets
(pod_allvolumes, pod_allvolumeMounts) = self.build_volumes( authinfo, userinfo, volume_type='pod_desktop', secrets_requirement=None, rules=rules, **kwargs)
(pod_allvolumes, pod_allvolumeMounts) = self.build_volumes( authinfo, userinfo, volume_type='pod_desktop', secrets_requirement=['all'], rules=rules, **kwargs)
list_pod_allvolumes = list( pod_allvolumes.values() )
list_pod_allvolumeMounts = list( pod_allvolumeMounts.values() )

Expand Down

0 comments on commit 176d94c

Please sign in to comment.