Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2060 from grapl-security/twunderlich/fix-plugin-s…
Browse files Browse the repository at this point in the history
…3-url

Fix s3 uri format so that its explicitly a s3 URI
  • Loading branch information
twunderlich-grapl authored Oct 18, 2022
2 parents 7f528df + c611380 commit 7228b83
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/rust/plugin-registry/src/server/deploy_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rust_proto::graplinc::grapl::api::plugin_registry::v1beta1::PluginType;

use super::{
plugin_nomad_job,
s3_url::get_s3_url,
s3_uri::get_s3_uri,
service::PluginRegistryServiceConfig,
};
use crate::{
Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn get_job(
let plugin_artifact_url = {
let key = &plugin.artifact_s3_key;
let bucket = &service_config.bucket_name;
get_s3_url(bucket, key)
get_s3_uri(bucket, key)
};
let passthru = service_config.passthrough_vars;
let plugin_type = PluginType::try_from(plugin.plugin_type.as_str())
Expand Down
2 changes: 1 addition & 1 deletion src/rust/plugin-registry/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ mod create_plugin;
mod deploy_plugin;
mod get_plugin_health;
mod plugin_nomad_job;
mod s3_url;
mod s3_uri;
pub mod service;
19 changes: 19 additions & 0 deletions src/rust/plugin-registry/src/server/s3_uri.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use grapl_config::env_helpers::ENV_ENDPOINT;

/// This gets a s3 URI to be used by Nomad's artifact stanza (in particular the grapl-plugin).
/// The underlying library, Hashicorp's [go-getter](https://github.com/hashicorp/go-getter) lib,
/// doesn't work with the `http://` schema prefix, but does work with an explicit s3 prefix `s3://`
/// or without a prefix. We've opted for the s3 prefix to be explicit.
pub fn get_s3_uri(bucket: &str, key: &str) -> String {
let local_endpoint = std::env::var(ENV_ENDPOINT).ok();
// If the above is specified, we're running locally against Localhost
// Otherwise, it's against prod S3; so we use the s3 URIs. Notably, the underlying go-getter
// lib does not seem to work with s3 object URLs (urls that start with http:// or https://),
// including the recommended virtual host style access.
// https://github.com/hashicorp/go-getter/issues/387 tracks updating the documentation.
// This is the s3 URI format used in the s3 console.
local_endpoint.map_or_else(
|| format!("s3://{bucket}.s3.amazonaws.com/{key}"),
|endpoint| format!("{endpoint}/{bucket}/{key}"),
)
}
13 changes: 0 additions & 13 deletions src/rust/plugin-registry/src/server/s3_url.rs

This file was deleted.

0 comments on commit 7228b83

Please sign in to comment.