A free open source IT asset/license management system
Remove OIDC just-in-time provisioning and clear static analysis findings
Rod Christiansen41632586b05e
diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.phpindex 2c660cdb9b..981e21ff5a 100644--- a/app/Providers/AuthServiceProvider.php+++ b/app/Providers/AuthServiceProvider.php@@ -107,6 +107,9 @@ class AuthServiceProvider extends ServiceProvider// Federated identity: a provider-agnostic OIDC bearer guard, layered// alongside Passport via the `auth:oidc,api` multi-guard. Inert until// config('oidc.enabled') is true, so this is purely additive.+ // `$name` is unused: Laravel fixes the driver-closure signature as+ // ($app, $name, $config), and the guard is named by config/auth.php.+ /** @SuppressWarnings(PHPMD.UnusedFormalParameter) */Auth::extend('oidc', function ($app, $name, array $config) {return new \App\Auth\OidcGuard(Auth::createUserProvider($config['provider']),diff --git a/app/Services/Oidc/OidcUserResolver.php b/app/Services/Oidc/OidcUserResolver.phpindex 0d6f3b45bc..81dc142983 100644--- a/app/Services/Oidc/OidcUserResolver.php+++ b/app/Services/Oidc/OidcUserResolver.php@@ -4,16 +4,15 @@ namespace App\Services\Oidc;use App\Models\User;use Illuminate\Support\Facades\Log;-use Illuminate\Support\Str;/*** Maps a validated OIDC token's claims to an existing Snipe-IT user. The* matched user's own permissions then apply unchanged -- this class grants no* privileges of its own.*- * Lookup mirrors the SAML path (by username, active + not soft-deleted). Unknown- * users are rejected unless just-in-time provisioning is explicitly enabled, in- * which case they are created with no extra permissions.+ * Lookup mirrors the SAML path (by username, active + not soft-deleted). A token+ * that resolves to no existing user is rejected -- there is no just-in-time+ * provisioning, so the IdP cannot conjure Snipe-IT accounts.*/class OidcUserResolver{@@ -35,10 +34,6 @@ class OidcUserResolverreturn $user;}- if (config('oidc.provision')) {- return $this->provision($claims, $username);- }-Log::warning('[OIDC] No active Snipe-IT user for token', ['username' => $username]);return null;@@ -56,21 +51,4 @@ class OidcUserResolverreturn ! empty($claims[$claimName]) ? (string) $claims[$claimName] : null;}-- protected function provision(array $claims, string $username): ?User- {- $user = new User;- $user->username = $username;- $user->email = $claims['email'] ?? '';- $user->first_name = $claims['given_name'] ?? $username;- $user->last_name = $claims['family_name'] ?? '';- $user->activated = true;- // Random unusable password -- these users authenticate only via OIDC.- $user->password = bcrypt(Str::random(40));- $user->save();-- Log::info('[OIDC] Just-in-time provisioned Snipe-IT user', ['username' => $username]);-- return $user;- }}diff --git a/config/oidc.php b/config/oidc.phpindex 035ee27248..ba997899bf 100644--- a/config/oidc.php+++ b/config/oidc.php@@ -52,10 +52,6 @@ return [// arrives in `preferred_username`.'username_claim' => env('OIDC_API_USERNAME_CLAIM', 'preferred_username'),- // Just-in-time provisioning of unknown users. Off by default; when on, a new- // user is created with no extra permissions (an admin grants them after).- 'provision' => env('OIDC_API_PROVISION', false),-// Clock-skew leeway (seconds) for exp/nbf validation.'leeway' => (int) env('OIDC_API_LEEWAY', 60),diff --git a/tests/Feature/Authentication/OidcApiAuthTest.php b/tests/Feature/Authentication/OidcApiAuthTest.phpindex 192c9f87d8..e5173c8f17 100644--- a/tests/Feature/Authentication/OidcApiAuthTest.php+++ b/tests/Feature/Authentication/OidcApiAuthTest.php@@ -16,6 +16,8 @@ use Tests\TestCase;* by a local RSA keypair. The validator's JWKS retrieval is stubbed with that* keypair's public key (the network/discovery path is unchanged in production),* so these tests never touch a network or a real IdP.+ *+ * @SuppressWarnings(PHPMD.TooManyMethods)*/class OidcApiAuthTest extends TestCase{@@ -39,6 +41,7 @@ class OidcApiAuthTest extends TestCase'private_key_bits' => 2048,'private_key_type' => OPENSSL_KEYTYPE_RSA,]);+ $privatePem = '';openssl_pkey_export($res, $privatePem);$this->privatePem = $privatePem;$publicPem = openssl_pkey_get_details($res)['key'];@@ -49,7 +52,6 @@ class OidcApiAuthTest extends TestCase'oidc.audiences' => [$this->audience],'oidc.algorithms' => ['RS256'],'oidc.username_claim' => 'preferred_username',- 'oidc.provision' => false,'oidc.leeway' => 60,]);@@ -57,8 +59,19 @@ class OidcApiAuthTest extends TestCase// hits the network; iss/aud/exp/signature validation still run for real.$this->app->instance(OidcTokenValidator::class, new class($publicPem, $this->kid) extends OidcTokenValidator{- public function __construct(private string $pub, private string $signingKid) {}+ private string $pub;+ private string $signingKid;++ public function __construct(string $pub, string $signingKid)+ {+ $this->pub = $pub;+ $this->signingKid = $signingKid;+ }++ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */protected function signingKeys(string $issuer): array{return [$this->signingKid => new Key($this->pub, 'RS256')];