Repository: quarkusio/quarkus
Issue: ConfigPhase.BUILD_AND_RUN_TIME_FIXED allows to set properties in JVM mode

## Describe the bug

A user [has reported](https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/http.20permission.20enabled.20runtime.20or.20buildtime.20property) that [enabling the HTTP permissions](https://quarkus.io/guides/security-authorization#disabling-permissions) is allowed in the JVM mode but not in the native mode:

`HttpBuildTimeConfig` -> `AuthConfig.permissions` -> `PolicyMappingConfig.enabled`

`HttpBuildTimeConfig` is a `ConfigRoot` in a `ConfigPhase.BUILD_AND_RUN_TIME_FIXED` so it explains why this property is shown with a lock on the all config page.

### Expected behavior
Setting properties at runtime should not work in `ConfigPhase.BUILD_AND_RUN_TIME_FIXED`.

`HttpBuildTimeConfig` should be split into `HttpBuildTimeConfig` which would only keep the `ConfigPhase.BUILD_AND_RUN_TIME_FIXED` properties and `HttpConfig` which would have all other properties which may be possible to override at runtime (if it is possible in principle for some HTTP properties)


Changed files:
core/test-extension/deployment/src/main/java/io/quarkus/extest/deployment/TestProcessor.java
core/test-extension/deployment/src/test/java/io/quarkus/extest/ConfiguredBeanTest.java
core/test-extension/deployment/src/test/java/io/quarkus/extest/ConfiguredBean.java
core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java
core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/TestAnnotation.java
core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/OverrideBuildTimeConfigSource.java

diff --git a/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java b/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java
index 2ad341c8594..7dfe2875873 100644
--- a/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java
+++ b/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java
@@ -389,7 +389,7 @@ public static final class GenerateOperation implements AutoCloseable {
             cc.getFieldCreator(C_BUILD_TIME_CONFIG_SOURCE)
                     .setModifiers(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL);
             final ResultHandle buildTimeConfigSource = clinit.newInstance(PCS_NEW, buildTimeValues,
-                    clinit.load("Build time config"), clinit.load(100));
+                    clinit.load("Build time config"), clinit.load(Integer.MAX_VALUE));
             clinit.writeStaticField(C_BUILD_TIME_CONFIG_SOURCE, buildTimeConfigSource);
 
             // the build time run time visible default values config source
@@ -483,7 +483,7 @@ public void run() {
                             reinit.load(entry.getValue()));
                 }
                 final ResultHandle buildTimeConfigSource = reinit.newInstance(PCS_NEW, buildTimeValues,
-                        reinit.load("Build time config = Reloaded"), reinit.load(100));
+                        reinit.load("Build time config = Reloaded"), reinit.load(Integer.MAX_VALUE));
                 // the build time config, which is for user use only (not used by us other than for loading converters)
                 final ResultHandle buildTimeBuilder = reinit.invokeStaticMethod(CU_CONFIG_BUILDER, reinit.load(true),
                         reinit.load(launchMode));
diff --git a/core/test-extension/deployment/src/main/java/io/quarkus/extest/deployment/TestProcessor.java b/core/test-extension/deployment/src/main/java/io/quarkus/extest/deployment/TestProcessor.java
index 964b48a7f56..dc8db706a2c 100644
--- a/core/test-extension/deployment/src/main/java/io/quarkus/extest/deployment/TestProcessor.java
+++ b/core/test-extension/deployment/src/main/java/io/quarkus/extest/deployment/TestProcessor.java
@@ -17,28 +17,19 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Base64;
-import java.util.Collection;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 import java.util.function.BooleanSupplier;
 
-import javax.enterprise.context.ApplicationScoped;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
 
-import org.jboss.jandex.AnnotationInstance;
-import org.jboss.jandex.ClassInfo;
-import org.jboss.jandex.DotName;
-import org.jboss.jandex.IndexView;
 import org.jboss.logging.Logger;
 
 import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
-import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem;
 import io.quarkus.arc.deployment.BeanContainerBuildItem;
-import io.quarkus.arc.deployment.BeanDefiningAnnotationBuildItem;
 import io.quarkus.deployment.annotations.BuildProducer;
 import io.quarkus.deployment.annotations.BuildStep;
 import io.quarkus.deployment.annotations.Record;
@@ -54,23 +45,16 @@
 import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedPackageBuildItem;
 import io.quarkus.extest.runtime.AdditionalStaticInitConfigSourceProvider;
 import io.quarkus.extest.runtime.FinalFieldReflectionObject;
-import io.quarkus.extest.runtime.IConfigConsumer;
 import io.quarkus.extest.runtime.RuntimeXmlConfigService;
-import io.quarkus.extest.runtime.TestAnnotation;
 import io.quarkus.extest.runtime.TestRecorder;
 import io.quarkus.extest.runtime.beans.CommandServlet;
 import io.quarkus.extest.runtime.beans.PublicKeyProducer;
-import io.quarkus.extest.runtime.config.AnotherPrefixConfig;
-import io.quarkus.extest.runtime.config.FooRuntimeConfig;
 import io.quarkus.extest.runtime.config.ObjectOfValue;
 import io.quarkus.extest.runtime.config.ObjectValueOf;
-import io.quarkus.extest.runtime.config.PrefixConfig;
 import io.quarkus.extest.runtime.config.TestBuildAndRunTimeConfig;
 import io.quarkus.extest.runtime.config.TestBuildTimeConfig;
 import io.quarkus.extest.runtime.config.TestConfigRoot;
-import io.quarkus.extest.runtime.config.TestRunTimeConfig;
 import io.quarkus.extest.runtime.config.XmlConfig;
-import io.quarkus.extest.runtime.config.named.PrefixNamedConfig;
 import io.quarkus.extest.runtime.logging.AdditionalLogHandlerValueFactory;
 import io.quarkus.extest.runtime.runtimeinitializedpackage.RuntimeInitializedClass;
 import io.quarkus.extest.runtime.subst.DSAPublicKeyObjectSubstitution;
@@ -83,8 +67,6 @@
  */
 public final class TestProcessor {
     static final Logger log = Logger.getLogger(TestProcessor.class);
-    static DotName TEST_ANNOTATION = DotName.createSimple(TestAnnotation.class.getName());
-    static DotName TEST_ANNOTATION_SCOPE = DotName.createSimple(ApplicationScoped.class.getName());
 
     TestConfigRoot configRoot;
     TestBuildTimeConfig buildTimeConfig;
@@ -100,16 +82,6 @@ FeatureBuildItem featureBuildItem() {
         return new FeatureBuildItem("test-extension");
     }
 
-    /**
-     * Register a custom bean defining annotation
-     *
-     * @return BeanDefiningAnnotationBuildItem
-     */
-    @BuildStep
-    BeanDefiningAnnotationBuildItem registerBeanDefiningAnnotations() {
-        return new BeanDefiningAnnotationBuildItem(TEST_ANNOTATION, TEST_ANNOTATION_SCOPE);
-    }
-
     /**
      * Register an additional log handler
      *
@@ -343,59 +315,6 @@ void checkConfig() {
         }
     }
 
-    /**
-     * Collect the beans with our custom bean defining annotation and configure them with the runtime config
-     *
-     * @param recorder - runtime recorder
-     * @param beanArchiveIndex - index of type information
-     * @param testBeanProducer - producer for located Class<IConfigConsumer> bean types
-     */
-    @BuildStep
-    @Record(STATIC_INIT)
-    void scanForBeans(TestRecorder recorder, BeanArchiveIndexBuildItem beanArchiveIndex,
-            BuildProducer<TestBeanBuildItem> testBeanProducer) {
-        IndexView indexView = beanArchiveIndex.getIndex();
-        Collection<AnnotationInstance> testBeans = indexView.getAnnotations(TEST_ANNOTATION);
-        for (AnnotationInstance ann : testBeans) {
-            ClassInfo beanClassInfo = ann.target().asClass();
-            try {
-                boolean isConfigConsumer = beanClassInfo.interfaceNames()
-                        .stream()
-                        .anyMatch(dotName -> dotName.equals(DotName.createSimple(IConfigConsumer.class.getName())));
-                if (isConfigConsumer) {
-                    Class<IConfigConsumer> beanClass = (Class<IConfigConsumer>) Class.forName(beanClassInfo.name().toString(),
-                            true, Thread.currentThread().getContextClassLoader());
-                    testBeanProducer.produce(new TestBeanBuildItem(beanClass));
-                    log.infof("The configured bean: %s", beanClass);
-                }
-            } catch (ClassNotFoundException e) {
-                log.warn("Failed to load bean class", e);
-            }
-        }
-    }
-
-    /**
-     * For each IConfigConsumer type, have the runtime recorder create a bean and pass in the runtime related configs
-     *
-     * @param recorder - runtime recorder
-     * @param testBeans - types of IConfigConsumer found
-     * @param beanContainer - bean container to create test bean in
-     * @param runTimeConfig - The RUN_TIME config phase root config
-     */
-    @BuildStep
-    @Record(RUNTIME_INIT)
-    void configureBeans(TestRecorder recorder, List<TestBeanBuildItem> testBeans,
-            BeanContainerBuildItem beanContainer,
-            TestRunTimeConfig runTimeConfig, FooRuntimeConfig fooRuntimeConfig, PrefixConfig prefixConfig,
-            PrefixNamedConfig prefixNamedConfig,
-            AnotherPrefixConfig anotherPrefixConfig) {
-        for (TestBeanBuildItem testBeanBuildItem : testBeans) {
-            Class<IConfigConsumer> beanClass = testBeanBuildItem.getConfigConsumer();
-            recorder.configureBeans(beanContainer.getValue(), beanClass, buildAndRunTimeConfig, runTimeConfig,
-                    fooRuntimeConfig, prefixConfig, prefixNamedConfig, anotherPrefixConfig);
-        }
-    }
-
     /**
      * Test for https://github.com/quarkusio/quarkus/issues/1633
      *
diff --git a/core/test-extension/deployment/src/test/java/io/quarkus/extest/ConfiguredBean.java b/core/test-extension/deployment/src/test/java/io/quarkus/extest/ConfiguredBean.java
index 50f29b7b7e2..a27512b6bdc 100644
--- a/core/test-extension/deployment/src/test/java/io/quarkus/extest/ConfiguredBean.java
+++ b/core/test-extension/deployment/src/test/java/io/quarkus/extest/ConfiguredBean.java
@@ -1,7 +1,8 @@
 package io.quarkus.extest;
 
-import io.quarkus.extest.runtime.IConfigConsumer;
-import io.quarkus.extest.runtime.TestAnnotation;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
 import io.quarkus.extest.runtime.config.AnotherPrefixConfig;
 import io.quarkus.extest.runtime.config.FooRuntimeConfig;
 import io.quarkus.extest.runtime.config.PrefixConfig;
@@ -9,34 +10,20 @@
 import io.quarkus.extest.runtime.config.TestRunTimeConfig;
 import io.quarkus.extest.runtime.config.named.PrefixNamedConfig;
 
-/**
- * A sample bean
- */
-@TestAnnotation
-public class ConfiguredBean implements IConfigConsumer {
-    volatile TestRunTimeConfig runTimeConfig;
-    volatile TestBuildAndRunTimeConfig buildTimeConfig;
-    volatile FooRuntimeConfig fooRuntimeConfig;
-    volatile PrefixConfig prefixConfig;
-    volatile PrefixNamedConfig prefixNamedConfig;
-    volatile AnotherPrefixConfig anotherPrefixConfig;
-
-    /**
-     * Called by runtime with the runtime config object
-     * 
-     * @param runTimeConfig
-     */
-    @Override
-    public void loadConfig(TestBuildAndRunTimeConfig buildTimeConfig, TestRunTimeConfig runTimeConfig,
-            FooRuntimeConfig fooRuntimeConfig, PrefixConfig prefixConfig, PrefixNamedConfig prefixNamedConfig,
-            AnotherPrefixConfig anotherPrefixConfig) {
-        this.buildTimeConfig = buildTimeConfig;
-        this.runTimeConfig = runTimeConfig;
-        this.fooRuntimeConfig = fooRuntimeConfig;
-        this.prefixConfig = prefixConfig;
-        this.prefixNamedConfig = prefixNamedConfig;
-        this.anotherPrefixConfig = anotherPrefixConfig;
-    }
+@ApplicationScoped
+public class ConfiguredBean {
+    @Inject
+    TestRunTimeConfig runTimeConfig;
+    @Inject
+    TestBuildAndRunTimeConfig buildTimeConfig;
+    @Inject
+    FooRuntimeConfig fooRuntimeConfig;
+    @Inject
+    PrefixConfig prefixConfig;
+    @Inject
+    PrefixNamedConfig prefixNamedConfig;
+    @Inject
+    AnotherPrefixConfig anotherPrefixConfig;
 
     public TestRunTimeConfig getRunTimeConfig() {
         return runTimeConfig;
diff --git a/core/test-extension/deployment/src/test/java/io/quarkus/extest/ConfiguredBeanTest.java b/core/test-extension/deployment/src/test/java/io/quarkus/extest/ConfiguredBeanTest.java
index 0977b03a3a2..47831946a1b 100644
--- a/core/test-extension/deployment/src/test/java/io/quarkus/extest/ConfiguredBeanTest.java
+++ b/core/test-extension/deployment/src/test/java/io/quarkus/extest/ConfiguredBeanTest.java
@@ -24,7 +24,6 @@
 
 import javax.inject.Inject;
 
-import org.eclipse.microprofile.config.ConfigProvider;
 import org.eclipse.microprofile.config.spi.ConfigSource;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
@@ -44,6 +43,7 @@
 import io.quarkus.extest.runtime.config.named.PrefixNamedConfig;
 import io.quarkus.test.QuarkusUnitTest;
 import io.restassured.RestAssured;
+import io.smallrye.config.ConfigValue;
 import io.smallrye.config.SmallRyeConfig;
 
 /**
@@ -316,11 +316,15 @@ public void testRtMapOfMap() {
 
     @Test
     public void buildTimeDefaults() {
-        // Source is only initialized once in runtime.
-        Assertions.assertEquals(1, OverrideBuildTimeConfigSource.counter.get());
-        // Test that build configRoot are not overridden by properties in runtime.
+        // Source is only initialized twice (one for static init and another one for runtime)
+        Assertions.assertEquals(2, OverrideBuildTimeConfigSource.counter.get());
+        // Test that build configRoot are not overridden by properties set in static or runtime init
         Assertions.assertEquals(1234567891L, buildAndRunTimeConfig.allValues.longPrimitive);
-        Assertions.assertEquals(0, ConfigProvider.getConfig().getValue("quarkus.btrt.all-values.long-primitive", Long.class));
+
+        ConfigValue value = config.getConfigValue("quarkus.btrt.all-values.long-primitive");
+        Assertions.assertEquals("1234567891", value.getValue());
+        Assertions.assertEquals("PropertiesConfigSource[source=Build time config]", value.getConfigSourceName());
+        Assertions.assertEquals(Integer.MAX_VALUE, value.getConfigSourceOrdinal());
     }
 
     @Test
@@ -335,11 +339,15 @@ public void testConfigDefaultValuesSourceOrdinal() {
         Optional<ConfigSource> source = config.getConfigSource("PropertiesConfigSource[source=Specified default values]");
         assertTrue(source.isPresent());
         ConfigSource defaultValues = source.get();
-
         assertEquals(Integer.MIN_VALUE + 100, defaultValues.getOrdinal());
 
-        // Should be the first
-        ConfigSource applicationProperties = config.getConfigSources().iterator().next();
+        ConfigSource applicationProperties = null;
+        for (ConfigSource configSource : config.getConfigSources()) {
+            if (configSource.getName().contains("application.properties")) {
+                applicationProperties = configSource;
+                break;
+            }
+        }
         assertNotNull(applicationProperties);
         assertEquals(1000, applicationProperties.getOrdinal());
 
diff --git a/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/TestAnnotation.java b/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/TestAnnotation.java
deleted file mode 100644
index 314e3ebc8aa..00000000000
--- a/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/TestAnnotation.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package io.quarkus.extest.runtime;
-
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-/**
- * Marker annotation for test configuration target beans
- */
-@Target({ TYPE })
-@Retention(RUNTIME)
-@Documented
-@Inherited
-public @interface TestAnnotation {
-}
diff --git a/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/OverrideBuildTimeConfigSource.java b/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/OverrideBuildTimeConfigSource.java
index f450442e253..bdc269e926f 100644
--- a/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/OverrideBuildTimeConfigSource.java
+++ b/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/OverrideBuildTimeConfigSource.java
@@ -6,11 +6,13 @@
 import org.eclipse.microprofile.config.ConfigProvider;
 import org.eclipse.microprofile.config.spi.ConfigSource;
 
+import io.quarkus.runtime.annotations.StaticInitSafe;
 import io.smallrye.config.common.MapBackedConfigSource;
 
 /**
  * Override a build time property in runtime.
  */
+@StaticInitSafe
 public class OverrideBuildTimeConfigSource extends MapBackedConfigSource {
     public static AtomicInteger counter = new AtomicInteger(0);