diff --git a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php
index dd4ae5f470..427a1cd39a 100644
--- a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php
+++ b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php
@@ -14,12 +14,16 @@
  * $conf['container_service_providers'] and required to prevent various services
  * from trying to retrieve data from storages that do not exist yet.
  */
-class InstallerServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
+class InstallerServiceProvider extends NormalInstallerServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
 
   /**
    * {@inheritdoc}
    */
   public function register(ContainerBuilder $container) {
+    // Do nothing if installation is finisihed.
+    if (!$this->isInstalling()) {
+      return;
+    }
     // Inject the special configuration storage for the installer.
     // This special implementation MUST NOT be used anywhere else than the early
     // installer environment.
@@ -68,6 +72,10 @@ public function register(ContainerBuilder $container) {
    * {@inheritdoc}
    */
   public function alter(ContainerBuilder $container) {
+    // Do nothing if installation is finisihed.
+    if (!$this->isInstalling()) {
+      return;
+    }
     // Disable Twig cache (php storage does not exist yet).
     $twig_config = $container->getParameter('twig.config');
     $twig_config['cache'] = FALSE;
diff --git a/core/lib/Drupal/Core/Installer/NormalInstallerServiceProvider.php b/core/lib/Drupal/Core/Installer/NormalInstallerServiceProvider.php
index c63b2d864f..6181641027 100644
--- a/core/lib/Drupal/Core/Installer/NormalInstallerServiceProvider.php
+++ b/core/lib/Drupal/Core/Installer/NormalInstallerServiceProvider.php
@@ -14,8 +14,23 @@ class NormalInstallerServiceProvider implements ServiceProviderInterface {
    * {@inheritdoc}
    */
   public function register(ContainerBuilder $container) {
-    // Use a performance optimised module extension list.
-    $container->getDefinition('extension.list.module')->setClass('Drupal\Core\Installer\InstallerModuleExtensionList');
+    if ($this->isInstalling()) {
+      // Use a performance optimised module extension list.
+      $container->getDefinition('extension.list.module')
+        ->setClass('Drupal\Core\Installer\InstallerModuleExtensionList');
+    }
+  }
+
+  /**
+   * Returns TRUE if a Drupal installation is currently being attempted.
+   *
+   * This is used to ensure that installer service providers do not affect the
+   * container once Drupal is installed.
+   *
+   * @return bool
+   */
+  protected function isInstalling() {
+    return drupal_installation_attempted();
   }
 
 }
diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
index 38e610c3b5..2e8562b3f1 100644
--- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
+++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
@@ -639,4 +639,13 @@ public function testGetDefaultDriveInstance() {
     $this->assertEquals([NULL, ['key1' => ['key2' => ['key3' => 3, 'key3.1' => 3.1]]]], $this->minkDefaultDriverArgs);
   }
 
+  /**
+   * Ensures we can't access modules we shouldn't be able to after install.
+   */
+  public function testProfileModules() {
+    $this->setExpectedException(\InvalidArgumentException::class, 'The module demo_umami_content does not exist.');
+    $this->assertFileExists('core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.info.yml');
+    \Drupal::service('extension.list.module')->getPathname('demo_umami_content');
+  }
+
 }
diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
index 2ba85e92e1..55ca1b8596 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
@@ -306,4 +306,15 @@ protected function tearDown() {
     }
   }
 
+  /**
+   * Ensures KernelTestBase tests can access module's in profiles.
+   */
+  public function testProfileModules() {
+    $this->assertFileExists('core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.info.yml');
+    $this->assertSame(
+      'core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.info.yml',
+      \Drupal::service('extension.list.module')->getPathname('demo_umami_content')
+    );
+  }
+
 }
