Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ENV Variables w/Values #3

Closed
metaskills opened this issue Jun 17, 2022 · 3 comments
Closed

Update ENV Variables w/Values #3

metaskills opened this issue Jun 17, 2022 · 3 comments

Comments

@metaskills
Copy link
Member

Thoughts on changing the way this project works by updated each matching ENV variable with the returned value. So in stead of this:

echo $FOO_PARAM
ssm_parameter:/my/parameter

We would have this. And every runtime can simply use the environment vs constructing a fetch to localhost.

echo $FOO_PARAM
my-parameter

A friend shared this project as an idea on how to tap into LD_PRELOAD to update environments before the "real" lambda function/application starts. Thoughts?

https://github.com/mmanciop/opentelemetry-injector

@metaskills
Copy link
Member Author

Little proof of concept work thanks to @hmadison

[dependencies]
redhook = "2.0"
libc = "0.2.126"
log = "0.4.17"

[lib]
name = "ssmhook"
crate_type = ["dylib"]
extern crate libc;

use std::ffi::CStr;
use std::ffi::CString;

redhook::hook! {
    unsafe fn getenv(name: *const libc::c_char) -> *mut libc::c_char => dangerously_mutate_getenv {
    let given_pointer = redhook::real!(getenv)(name);
    if given_pointer.is_null() {
        return given_pointer;
    }
    let given_name = CStr::from_ptr(name).to_str().unwrap();
    let given_value = CStr::from_ptr(given_pointer).to_str().unwrap();
    println!("Got: {} / {}", given_name, given_value);
    if given_name == "HELLO" {
        // https://doc.rust-lang.org/std/ffi/struct.CStr.html#method.as_ptr
        let result = CString::new("WORLD").unwrap();
        return result.into_raw();
    }
        return given_pointer;
    }
}

@metaskills
Copy link
Member Author

@metaskills
Copy link
Member Author

Latest main has a working prototype. The sequence diagram is not needed because every extension inits before the runtime init. I tested this too by putting a sleep in the extension prior to SSM parameter fetching with a puts at the beginning of the runtime handler.

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

No branches or pull requests

1 participant