Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"archive/zip"
"fmt"
"io"
"log"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -106,6 +107,15 @@ func getLocalJar(url string) (string, error) {
return jarPath, nil
}

// Issue warning when downloading from public repositories
if strings.Contains(url, "repo.maven.apache.org") ||
strings.Contains(url, "repo1.maven.org") ||
strings.Contains(url, "maven.google.com") ||
strings.Contains(url, "maven-central.storage-download.googleapis.com") {
log.Printf("WARNING: Downloading JAR file from public repository: %s. "+
"This may pose security risks or cause instability due to repository availability. Consider pre-staging dependencies or using private mirrors.", url)
}

resp, err := http.Get(string(url))
if err != nil {
return "", err
Expand Down Expand Up @@ -334,6 +344,16 @@ func (j *jarGetter) getJar(gradleTarget, version string) (string, error) {
gradleTarget)
}

// Issue warning when downloading from public repositories
fullURLStr := string(fullURL)
if strings.Contains(fullURLStr, "repo.maven.apache.org") ||
strings.Contains(fullURLStr, "repo1.maven.org") ||
strings.Contains(fullURLStr, "maven.google.com") ||
strings.Contains(fullURLStr, "maven-central.storage-download.googleapis.com") {
log.Printf("WARNING: Downloading JAR file from public repository: %s. "+
"This may pose security risks or cause instability due to repository availability. Consider pre-staging dependencies or using private mirrors.", fullURLStr)
}

resp, err := http.Get(string(fullURL))
if err != nil {
return "", err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ public AggregateFn loadAggregateFunction(List<String> functionPath, String jarPa
*/
private File downloadFile(String inputPath, String mimeType) throws IOException {
Preconditions.checkArgument(!inputPath.isEmpty(), "Path cannot be empty.");

Comment thread
Abacn marked this conversation as resolved.
// Issue warning when downloading from public repositories
if (inputPath.startsWith("http://") || inputPath.startsWith("https://")) {
if (inputPath.contains("repo.maven.apache.org")
|| inputPath.contains("repo1.maven.org")
|| inputPath.contains("maven.google.com")
|| inputPath.contains("maven-central.storage-download.googleapis.com")) {
LOG.warn(
"WARNING: Downloading JAR file from public repository: {}. "
+ "This may pose security risks or cause instability due to repository availability. Consider pre-staging dependencies or using private mirrors.",
inputPath);
}
}

ResourceId inputResource = FileSystems.matchNewResource(inputPath, false /* is directory */);
try (ReadableByteChannel inputChannel = FileSystems.open(inputResource)) {
File outputFile = File.createTempFile("sql-udf-", inputResource.getFilename());
Expand Down
26 changes: 24 additions & 2 deletions sdks/python/apache_beam/utils/subprocess_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,10 @@ def _really_stop_process(process_and_endpoint):
class JavaJarServer(SubprocessServer):

MAVEN_CENTRAL_REPOSITORY = 'https://repo.maven.apache.org/maven2'
MAVEN_STAGING_REPOSITORY = 'https://repository.apache.org/content/groups/staging' # pylint: disable=line-too-long
GOOGLE_MAVEN_MIRROR = 'https://maven-central.storage-download.googleapis.com/maven2' # pylint: disable=line-too-long
MAVEN_STAGING_REPOSITORY = (
'https://repository.apache.org/content/groups/staging')
GOOGLE_MAVEN_MIRROR = (
'https://maven-central.storage-download.googleapis.com/maven2')
BEAM_GROUP_ID = 'org.apache.beam'
JAR_CACHE = os.path.expanduser("~/.apache_beam/cache/jars")

Expand Down Expand Up @@ -431,6 +433,26 @@ def _download_jar_to_cache(
cached_jar_path (str): The local path where the jar should be cached.
user_agent (str): The user agent to use when downloading.
"""
# Issue warning when downloading from public repositories
public_repos = [
cls.MAVEN_CENTRAL_REPOSITORY,
cls.GOOGLE_MAVEN_MIRROR,
]

if any(download_url.startswith(repo) for repo in public_repos):
_LOGGER.warning(

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.

Could logging the destination path (instead of url path) be more helpful in terms of instructing user where to stage the jar?

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.

Good idea. Log both now.

" WARNING: Apache Beam is downloading dependencies from a "
"public repository at runtime.\n"
" This may pose security risks or cause instability due to "
"repository availability.\n"
" URL: %s\n"
" Destination: %s\n"
" Consider pre-staging dependencies or using a private repository "
"mirror.\n"
" For more information, see: "
"https://beam.apache.org/documentation/sdks/python-dependencies/",

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 think https://beam.apache.org/documentation/sdks/python-dependencies/ contains relevant information for this manner (for now). But we can add recommendation there

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.

Agree. Just want to use that as a placeholder.

download_url,
cached_jar_path)
try:
url_read = FileSystems.open(download_url)
except ValueError:
Expand Down
26 changes: 26 additions & 0 deletions sdks/python/apache_beam/yaml/yaml_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
from apache_beam.yaml import yaml_utils
from apache_beam.yaml.yaml_errors import maybe_with_exception_handling_transform_fn

_LOGGER = logging.getLogger(__name__)


class NotAvailableWithReason:
"""A False value that provides additional content.
Expand Down Expand Up @@ -1322,6 +1324,18 @@ def _create_venv_from_scratch(
venv_python = os.path.join(venv, 'bin', 'python')
venv_pip = os.path.join(venv, 'bin', 'pip')
subprocess.run([venv_python, '-m', 'ensurepip'], check=True)
# Issue warning when installing packages from PyPI
_LOGGER.warning(
" WARNING: Apache Beam is installing Python packages "
"from PyPI at runtime.\n"
" This may pose security risks or cause instability due to "
"repository availability.\n"
" Packages: %s\n"
" Consider pre-staging dependencies or using a private "
"repository mirror.\n"
" For more information, see: "
"https://beam.apache.org/documentation/sdks/python-dependencies/",
', '.join(packages))
subprocess.run([venv_pip, 'install'] + packages, check=True)
with open(venv + '-requirements.txt', 'w') as fout:
fout.write('\n'.join(packages))
Expand All @@ -1342,6 +1356,18 @@ def _create_venv_from_clone(
clonable_venv = cls._create_venv_to_clone(base_python)
clonevirtualenv.clone_virtualenv(clonable_venv, venv)
venv_pip = os.path.join(venv, 'bin', 'pip')
# Issue warning when installing packages from PyPI
_LOGGER.warning(
" WARNING: Apache Beam is installing Python packages "
"from PyPI at runtime.\n"
" This may pose security risks or cause instability due to "
"repository availability.\n"
" Packages: %s\n"
" Consider pre-staging dependencies or using a private "
"repository mirror.\n"
" For more information, see: "
"https://beam.apache.org/documentation/sdks/python-dependencies/",
', '.join(packages))
subprocess.run([venv_pip, 'install'] + packages, check=True)
with open(venv + '-requirements.txt', 'w') as fout:
fout.write('\n'.join(packages))
Expand Down
Loading