Skip to content

Commit 0f0f5aa

Browse files
authored
Pass in private_data_dir when project update is on K8S
In OCP/K8S, projects run in the task pod's ee container. The private_data_dir is not extracted to /runner. Instead, the project update runs directly from the mounted in private_data_dir, e.g. /tmp/awx_1_abcd. When injecting a credential that uses extra vars, we pass the private_data_dir as as the container_root, so that the correct command line argument is generated, e.g. "-e /tmp/awx_1_abcd/env/extra_var_file". Signed-off-by: Seth Foster <[email protected]>
1 parent bc12fa2 commit 0f0f5aa

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

awx/api/views/analytics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from awx.api.permissions import AnalyticsPermission
1111
from awx.api.versioning import reverse
1212
from awx.main.utils import get_awx_version
13-
from awx.main.utils.analytics_proxy import OIDCClient, DEFAULT_OIDC_ENDPOINT
13+
from awx.main.utils.analytics_proxy import OIDCClient, DEFAULT_OIDC_TOKEN_ENDPOINT
1414
from rest_framework import status
1515

1616
from collections import OrderedDict
@@ -205,7 +205,7 @@ def _send_to_analytics(self, request, method):
205205
try:
206206
rh_user = self._get_setting('REDHAT_USERNAME', None, ERROR_MISSING_USER)
207207
rh_password = self._get_setting('REDHAT_PASSWORD', None, ERROR_MISSING_PASSWORD)
208-
client = OIDCClient(rh_user, rh_password, DEFAULT_OIDC_ENDPOINT, ['api.console'])
208+
client = OIDCClient(rh_user, rh_password, DEFAULT_OIDC_TOKEN_ENDPOINT, ['api.console'])
209209
response = client.make_request(
210210
method,
211211
url,

awx/main/analytics/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from awx.main.models import Job
2323
from awx.main.access import access_registry
2424
from awx.main.utils import get_awx_http_client_headers, set_environ, datetime_hook
25-
from awx.main.utils.analytics_proxy import OIDCClient, DEFAULT_OIDC_ENDPOINT
25+
from awx.main.utils.analytics_proxy import OIDCClient, DEFAULT_OIDC_TOKEN_ENDPOINT
2626

2727
__all__ = ['register', 'gather', 'ship']
2828

@@ -379,7 +379,7 @@ def ship(path):
379379
with set_environ(**settings.AWX_TASK_ENV):
380380
if rh_user and rh_password:
381381
try:
382-
client = OIDCClient(rh_user, rh_password, DEFAULT_OIDC_ENDPOINT, ['api.console'])
382+
client = OIDCClient(rh_user, rh_password, DEFAULT_OIDC_TOKEN_ENDPOINT, ['api.console'])
383383
response = client.make_request("POST", url, headers=s.headers, files=files, verify=settings.INSIGHTS_CERT_PATH, timeout=(31, 31))
384384
except requests.RequestException:
385385
logger.error("Automation Analytics API request failed, trying base auth method")

awx/main/models/credential.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,10 @@ def load_plugin(cls, ns, plugin):
550550
# TODO: User "side-loaded" credential custom_injectors isn't supported
551551
ManagedCredentialType.registry[ns] = SimpleNamespace(namespace=ns, name=plugin.name, kind='external', inputs=plugin.inputs, backend=plugin.backend)
552552

553-
def inject_credential(self, credential, env, safe_env, args, private_data_dir):
553+
def inject_credential(self, credential, env, safe_env, args, private_data_dir, container_root=None):
554554
from awx_plugins.interfaces._temporary_private_inject_api import inject_credential
555555

556-
inject_credential(self, credential, env, safe_env, args, private_data_dir)
556+
inject_credential(self, credential, env, safe_env, args, private_data_dir, container_root=container_root)
557557

558558

559559
class CredentialTypeHelper:

awx/main/tasks/jobs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,13 @@ def run(self, pk, **kwargs):
522522

523523
credentials = self.build_credentials_list(self.instance)
524524

525+
container_root = None
526+
if settings.IS_K8S and isinstance(self.instance, ProjectUpdate):
527+
container_root = private_data_dir
528+
525529
for credential in credentials:
526530
if credential:
527-
credential.credential_type.inject_credential(credential, env, self.safe_cred_env, args, private_data_dir)
531+
credential.credential_type.inject_credential(credential, env, self.safe_cred_env, args, private_data_dir, container_root=container_root)
528532

529533
self.runner_callback.safe_env.update(self.safe_cred_env)
530534

awx/main/utils/analytics_proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import requests
1212

13-
DEFAULT_OIDC_ENDPOINT = 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token'
13+
DEFAULT_OIDC_TOKEN_ENDPOINT = 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token'
1414

1515

1616
class TokenError(requests.RequestException):

0 commit comments

Comments
 (0)