<p>I hava a java <code>spring.boot</code> application that uses Kubernetes, I'we configured this <code>.yaml</code> file</p>

<pre><code>- name: ACTUATOR_USERNAME
  valueFrom:
    secretKeyRef:
      name: actuator
      key: username
- name: ACTUATOR_PASSWORD
  valueFrom:
    secretKeyRef:
      name: actuator
      key: password
</code></pre>

<p>added this attributes to my <code>application.propertis</code></p>

<pre><code>security.user.name=${ACTUATOR_USERNAME}
security.user.password=${ACTUATOR_PASSWORD}
</code></pre>

<p>secret is created at server side, how do I retrieve this values inside my class</p>

<pre><code>package com.greenqloud.usage.healthcheck;

import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class ActuatorSecurity extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests()
                .anyRequest().hasRole("USER")
                .and()
                .httpBasic();
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        System.out.println("actuator username: " + System.getenv("ACTUATOR_USERNAME"));
        System.out.println("actuator password: " + System.getenv("ACTUATOR_PASSWORD"));

        auth.inMemoryAuthentication()
                .withUser("actuator").password("{noop}actuator123").roles("USER");
    }
}
</code></pre>

<p>the only way I have found is to use the <code>System.out.getenv("ACTUATOR_USERNAME")</code> but I'm sure there is a better way to achieve this?</p>

JonB
<p>I am agree with @Kuikiker about getenv(). But one question why do u want to store credential in env variable. Unless u have some special need I believe you will be better off store them in your application.properties with encrypted value. I usually use jasypt encipher for that (<a href="https://www.baeldung.com/spring-boot-jasypt" rel="nofollow noreferrer">https://www.baeldung.com/spring-boot-jasypt</a>). 
Hope this helps.</p>
