Skip to content

Conversation

@adamdelman
Copy link
Contributor

@adamdelman adamdelman commented Nov 4, 2025

📝 Description

Extend Kaniko build support to handle S3 build-context sources and improve how builder environment variables are generated.
Also standardize logging calls in builder flows and ensure Kubernetes pod environments are always initialized as typed lists.


🛠️ Changes Made

Kubernetes Helper

  • Initialize Pod.env as a typed list (list[V1EnvVar]) instead of None to ensure safe and consistent mutation.

Builder

  • Introduce S3 context detection:
    • Add is_s3_source flag.
    • Refine source-scheme logic to treat s3:// similarly to local/v3io contexts.
  • Integrate new _enrich_kaniko_env_for_s3_context():
    • When the build context is s3://, set AWS_REGION using:
      • existing env vars → or process env → or fallback "default-region".
    • Only if no real region is found (fallback case), also add S3_FORCE_PATH_STYLE=true for MinIO compatibility.
  • Replace all mlrun.utils.logger.* calls with mlrun.utils.helpers.logger.* for consistent structured logging.
  • Update _generate_builder_env():
    • Accept list-style builder env ([{name, value}]) instead of a dict.
    • Convert entries into V1EnvVar objects.
    • Merge with project secrets, avoiding duplicates based on the env name.

🧪 Testing

  • Verified build flows with:
    • s3:// → correct region inference and MinIO path-style injection.
    • v3io://, local paths, and http:// → unchanged behavior.
  • Confirmed builder env generation correctly merges user env and project secrets.
  • Ensured updated logging source prints structured log fields as expected.

🔗 References


🚨 Breaking Changes?

  • No

🔍 Additional Notes

  • Improves robustness for S3/MinIO user workflows without requiring extra configuration.
  • Eliminates inconsistencies around builder environment mutation and logging.

- Enable S3 build context in Kaniko:
  - Add _enrich_kaniko_env_for_s3_context() to auto-set AWS_REGION=us-east-1
    and S3_FORCE_PATH_STYLE=true when using s3://
  - Pass builder env vars to Kaniko pod and convert AWS creds to secrets

- K8s pod refactor:
  - Rename BasePod → Pod
  - Maintain explicit env list and add add_env_var()
  - Implement replace_env_vars_with_secrets() and _create_secret_for_env_var()
    to materialize sensitive env vars as K8s secrets

- Builder / build flow improvements:
  - Accept env from request or function spec (`builder_env` fallback to `spec.env`)
  - Normalize builder env handling and logging via mlrun.utils.helpers.logger
  - Call function.try_auto_mount_based_on_config() before deploy
  - Treat s3://, v3io://, http(s):// sources distinctly; mount/copy as needed
  - Generate project secret-backed envs without overriding provided vars

https://iguazio.atlassian.net/browse/CEML-520
@adamdelman adamdelman changed the title Adamd/ceml 520 [Kaniko] add S3 Kaniko context + secret env; refactor BasePod→Pod Nov 4, 2025
@adamdelman adamdelman marked this pull request as ready for review November 4, 2025 22:59
@adamdelman adamdelman requested review from a team and quaark as code owners November 4, 2025 22:59
Copy link
Member

@liranbg liranbg left a comment

Choose a reason for hiding this comment

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

The PR incorporate few changes at once

  1. Fix for s3 region/force path
  2. Env to secrets
  3. Access key handling

This PR needs to be broken into smaller prs, each has its own risks and need to be carefully taken care of. for the (2) I am not sure I udnerstand the reason behind it. for (3) it seems to be incomplete and also, why is it needed? and for (1) - I think the safest way to proceed is to check if we can already can overcome the issue by providing explicit kaniko build args.

Comment on lines 1681 to 1682
def add_env_var(self, env_var: client.V1EnvVar):
self.env.append(env_var)
Copy link
Member

Choose a reason for hiding this comment

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

the operation is not idempotent and prone to duplicate envvars

Copy link
Contributor Author

@adamdelman adamdelman Nov 5, 2025

Choose a reason for hiding this comment

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

Neither is add_volume, why do we need it to be idempotent?

Comment on lines 1744 to 1749
secret_env_var = self._create_secret_for_env_var(
name=env_var.name,
value=env_var.value,
k8s_helper=k8s_helper,
)
self.env[index] = secret_env_var
Copy link
Member

Choose a reason for hiding this comment

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

what component is responsible to remove those secret later on? if I have 100 envvars, will it create 100 secrets? what's the reasoning behind it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This exactly the same as we do in mlrun_pipelines.common.ops._replace_env_vars_with_secrets, which was added in this PR you approved, where we create obfuscate secret env vars for each pipeline run.
The reasoning is that we do not want AWS/V3IO credentials to be visible on pod YAML's.

Comment on lines 1801 to 1804
secret_name, _ = k8s_helper.store_auth_secret(
username=name,
access_key=value,
)
Copy link
Member

Choose a reason for hiding this comment

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

does that aligned with igz4/oauth/igz3 expectations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, this is the same as mlrun_pipelines.common.ops._replace_env_vars_with_secrets

Comment on lines 1236 to 1237
name="AWS_REGION",
value="us-east-1",
Copy link
Member

Choose a reason for hiding this comment

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

why defaulting to this region?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because kaniko expects there to be a region set, even for minio, and this is the default AWS region.

Copy link
Member

Choose a reason for hiding this comment

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

Because kaniko expects there to be a region set, even for minio, and this is the default AWS region.

not 100%, on aws - admin can set its default region. I suggest to not default ourselves by either get it using aws (perhpas using aws command on init container / mlrun configuration) but def not hardcoded

@adamdelman
Copy link
Contributor Author

The PR incorporate few changes at once

  1. Fix for s3 region/force path
  2. Env to secrets
  3. Access key handling

This PR needs to be broken into smaller prs, each has its own risks and need to be carefully taken care of. for the (2) I am not sure I udnerstand the reason behind it. for (3) it seems to be incomplete and also, why is it needed? and for (1) - I think the safest way to proceed is to check if we can already can overcome the issue by providing explicit kaniko build args.

@liranbg
The reason for adding item number 2 is that we are adding sensitive credentials to the kaniko pod, and I don't want the to be visible in the pod yaml.
Item number 3 was not really added, if you look carefully it was already there , in this code block:

        "V3IO_ACCESS_KEY", auth_info.data_session or auth_info.access_key
    )
    username = builder_env.get("V3IO_USERNAME", auth_info.username)```
 The only difference is that now I also obfuscate these if they exist.

@adamdelman adamdelman changed the title [Kaniko] add S3 Kaniko context + secret env; refactor BasePod→Pod [Kaniko] Add S3/MinIO Build Context Support and Improve Builder Environment Handling Nov 6, 2025
@adamdelman adamdelman requested a review from liranbg November 9, 2025 08:07
@adamdelman adamdelman self-assigned this Nov 9, 2025
Comment on lines 1236 to 1237
name="AWS_REGION",
value="us-east-1",
Copy link
Member

Choose a reason for hiding this comment

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

Because kaniko expects there to be a region set, even for minio, and this is the default AWS region.

not 100%, on aws - admin can set its default region. I suggest to not default ourselves by either get it using aws (perhpas using aws command on init container / mlrun configuration) but def not hardcoded


# MinIO requires path-style URLs
already_has_path_style = any(
env.name == "S3_FORCE_PATH_STYLE" and env.value for env in env_vars
Copy link
Member

Choose a reason for hiding this comment

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

It is not 100% safe for "new" aws regions not supporting this ENV/configuration as they require virtual-host path. maybe we can force this configuration when we deploy against minio (mlrun ce-like configuration) - but not when working natively against s3

@adamdelman adamdelman requested a review from liranbg November 26, 2025 13:29
Copy link
Member

@liranbg liranbg left a comment

Choose a reason for hiding this comment

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

looking better, worth adding some ut use cases coverage to cover conventional flows

@adamdelman adamdelman requested a review from liranbg December 1, 2025 13:40
@liranbg liranbg merged commit 8370daa into mlrun:development Dec 2, 2025
13 checks passed
@adamdelman adamdelman deleted the adamd/CEML-520 branch December 2, 2025 12:35
liranbg added a commit that referenced this pull request Dec 14, 2025
…er Environment Handling" (#9052)

Reverts #8849

Due to
1. https://iguazio.atlassian.net/browse/ML-11743
2. https://iguazio.atlassian.net/browse/ML-11731

Overall, there are few issues with this PR as it enriches kaniko pod
with s3 information and ignoring project secrets.

PR needs to be rewritten and intensively covered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants