Skip to content

[hotfix] Validate jarURI in DefaultValidator#1104

Merged
gyfora merged 2 commits intoapache:mainfrom
oscerd:validate-jar-uri
Apr 28, 2026
Merged

[hotfix] Validate jarURI in DefaultValidator#1104
gyfora merged 2 commits intoapache:mainfrom
oscerd:validate-jar-uri

Conversation

@oscerd
Copy link
Copy Markdown
Contributor

@oscerd oscerd commented Apr 28, 2026

What

Validate the jarURI field on FlinkSessionJob submission: reject malformed URIs, schemes outside an allowlist, and http/https URIs whose host resolves to loopback, link-local, site-local, wildcard or multicast addresses. FlinkDeployment is intentionally not validated, since application clusters reference a JAR shipped inside the image (e.g. local://) and the operator never fetches it.

Config options

Both options are operator-level (SECTION_SYSTEM), resolved via FlinkOperatorConfiguration so a user-supplied flinkConfiguration in a CR cannot override them.

  • kubernetes.operator.user.artifacts.allowed-schemes (List<String>, default https)
  • kubernetes.operator.user.artifacts.disallow-restricted-hosts (Boolean, default true)

Tests

  • mvn -pl flink-kubernetes-operator test → 2133 / 0
  • mvn -pl flink-kubernetes-webhook test → 105 / 0
  • mvn clean install -DskipTests (full reactor) → BUILD SUCCESS

DefaultValidatorTest covers:

  • testJarUriSchemeValidation and testJarUriHostValidation — direct unit tests on the static helper (allowed/disallowed schemes, malformed URIs, missing schemes, loopback/link-local/site-local/wildcard/multicast hosts, opt-out flag).
  • testSessionJobJarUriValidationUsesOperatorConfig — verifies the validator reads the allowlist from the operator-level configuration and that a CR-supplied override of those keys is ignored.

Extend DefaultValidator.validateJobSpec to inspect the JobSpec
jarURI: malformed URIs are rejected, the scheme must be in a
configurable allowlist, and for http/https the host must not
resolve to loopback, link-local, site-local, wildcard or
multicast addresses.

Two new config options control the behaviour:
 - kubernetes.operator.user.artifacts.allowed-schemes
   (List<String>, default: "https", "local")
 - kubernetes.operator.user.artifacts.disallow-restricted-hosts
   (Boolean, default: true)

Update the FlinkSessionJob overview docs (en and zh) to describe
the new defaults and the override knobs, and regenerate the
operator config reference.

Signed-off-by: Andrea Cosentino <ancosen@gmail.com>

Configuration configuration = Configuration.fromMap(confMap);

Optional<String> jarUriError = validateJarURI(job.getJarURI(), configuration);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't really think that we should validate Application jarURIs here. I think session job validation makes sense because of the http download and local access on the operator pod but for applications these don't really matter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in c38f8bd. Moved the call out of validateJobSpec so application clusters are no longer touched, and added it to validateSessionJobOnly which runs on every session job submission.

</tr>
<tr>
<td><h5>kubernetes.operator.user.artifacts.allowed-schemes</h5></td>
<td style="word-wrap: break-word;">"https";<wbr>"local"</td>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if we remove application validation then local can be removed as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. local is gone from the default allowlist (default is now https only), and the option moved to the system section.

+ "schemes (such as 's3' or 'hdfs') can extend this list. "
+ "Scheme matching is case-insensitive.");

@Documentation.Section(SECTION_DYNAMIC)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These configs should go into SECTION_SYSTEM and be resolved in FlinkOperatorConfiguration otherwise the user would be able to override them from their CR's config

Copy link
Copy Markdown
Contributor Author

@oscerd oscerd Apr 28, 2026

Choose a reason for hiding this comment

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

Good catch, done. Both options are now SECTION_SYSTEM, resolved via FlinkOperatorConfiguration.fromConfiguration (new jarUriAllowedSchemes / jarUriDisallowRestrictedHosts fields), and read by the validator from configManager.getOperatorConfiguration(). A new test in DefaultValidatorTest#testSessionJobJarUriValidationUsesOperatorConfig confirms a CR-supplied override of these keys is ignored.

- Drop jarURI validation for FlinkDeployment; only FlinkSessionJob is
  validated since application clusters do not fetch the jar through
  the operator pod.
- Move JAR_URI_ALLOWED_SCHEMES and JAR_URI_DISALLOW_RESTRICTED_HOSTS
  to SECTION_SYSTEM and resolve them via FlinkOperatorConfiguration
  so a user-supplied flinkConfiguration in a CR cannot override the
  operator-level allowlist.
- Drop "local" from the default allowlist now that application
  clusters bypass validation; default is "https" only.
- Switch the static validateJarURI helper to take a Collection of
  allowed schemes and a boolean directly; call it from
  validateSessionJobOnly via the resolved operator configuration.
- Update tests: replace FlinkDeployment-based jarURI tests with
  direct unit tests on the static helper plus a session-job
  integration test that verifies a CR override is ignored.
- Add SAMPLE_SESSION_JOB_JAR test constant to keep existing session
  job test fixtures valid under the stricter default allowlist.
- Refresh docs (en + zh) and regenerate the operator config
  reference; the two options now appear under the system section.

Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
@gyfora gyfora merged commit add7fb3 into apache:main Apr 28, 2026
120 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants