diff --git a/app/Http/Controllers/Admin/NodeAutoDeployController.php b/app/Http/Controllers/Admin/NodeAutoDeployController.php index 3ae34d257..e7c9cd6af 100644 --- a/app/Http/Controllers/Admin/NodeAutoDeployController.php +++ b/app/Http/Controllers/Admin/NodeAutoDeployController.php @@ -6,7 +6,6 @@ use Illuminate\Http\Request; use Pterodactyl\Models\Node; use Pterodactyl\Models\ApiKey; use Illuminate\Http\JsonResponse; -use Pterodactyl\Services\Acl\Api\AdminAcl; use Pterodactyl\Http\Controllers\Controller; use Illuminate\Contracts\Encryption\Encrypter; use Pterodactyl\Services\Api\KeyCreationService; @@ -23,8 +22,8 @@ class NodeAutoDeployController extends Controller } /** - * Generates a new API key for the logged-in user with only permission to read - * node configurations, and returns that as the deployment key for a node. + * Generates a new API key for the logged-in user with read and write permission + * to nodes, and returns that as the deployment key for a node. * * @throws \Pterodactyl\Exceptions\Model\DataValidationException */ @@ -32,20 +31,18 @@ class NodeAutoDeployController extends Controller { $key = ApiKey::query() ->where('user_id', $request->user()->id) - ->where('node_id', $node->id) ->where('key_type', ApiKey::TYPE_APPLICATION) - ->where('r_nodes', AdminAcl::READ_CONFIGURATION) + ->where('r_nodes', 3) ->first(); - // We couldn't find a key that exists for this user with only permission for - // reading node configurations. Go ahead and create it now. + // We couldn't find a key that exists for this user with read and write + // permission for nodes. Go ahead and create it now. if (!$key) { $key = $this->keyCreationService->setKeyType(ApiKey::TYPE_APPLICATION)->handle([ 'user_id' => $request->user()->id, - 'node_id' => $node->id, 'memo' => 'Automatically generated node deployment key.', 'allowed_ips' => [], - ], ['r_nodes' => AdminAcl::READ_CONFIGURATION]); + ], ['r_nodes' => 3]); } return new JsonResponse([ diff --git a/app/Http/Requests/Admin/Api/StoreApplicationApiKeyRequest.php b/app/Http/Requests/Admin/Api/StoreApplicationApiKeyRequest.php index e5a5d1046..f451239e6 100644 --- a/app/Http/Requests/Admin/Api/StoreApplicationApiKeyRequest.php +++ b/app/Http/Requests/Admin/Api/StoreApplicationApiKeyRequest.php @@ -16,13 +16,9 @@ class StoreApplicationApiKeyRequest extends AdminFormRequest { $modelRules = ApiKey::getRules(); - $rules = collect(AdminAcl::getResourceList())->mapWithKeys(function ($resource) use ($modelRules) { + return collect(AdminAcl::getResourceList())->mapWithKeys(function ($resource) use ($modelRules) { return [AdminAcl::COLUMN_IDENTIFIER . $resource => $modelRules['r_' . $resource]]; })->merge(['memo' => $modelRules['memo']])->toArray(); - - $rules['r_' . AdminAcl::RESOURCE_NODES] = ['integer', 'in:0,1,3']; - - return $rules; } public function attributes(): array diff --git a/app/Http/Requests/Api/Application/Nodes/GetNodeConfigurationRequest.php b/app/Http/Requests/Api/Application/Nodes/GetNodeConfigurationRequest.php index f7485f741..e632698de 100644 --- a/app/Http/Requests/Api/Application/Nodes/GetNodeConfigurationRequest.php +++ b/app/Http/Requests/Api/Application/Nodes/GetNodeConfigurationRequest.php @@ -2,25 +2,9 @@ namespace Pterodactyl\Http\Requests\Api\Application\Nodes; -use Pterodactyl\Models\Node; -use Pterodactyl\Models\ApiKey; use Pterodactyl\Services\Acl\Api\AdminAcl; class GetNodeConfigurationRequest extends GetNodesRequest { protected int $permission = AdminAcl::WRITE; - - public function authorize(): bool - { - $token = $this->user()->currentAccessToken(); - if ($token instanceof ApiKey && AdminAcl::check($token, $this->resource, AdminAcl::READ_CONFIGURATION)) { - $node = $this->parameter('node', Node::class); - - if ($token->node_id === $node->id) { - return true; - } - } - - return parent::authorize(); - } } diff --git a/app/Models/ApiKey.php b/app/Models/ApiKey.php index 4505c3fcb..45ea6a1be 100644 --- a/app/Models/ApiKey.php +++ b/app/Models/ApiKey.php @@ -14,7 +14,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; * * @property int $id * @property int $user_id - * @property int|null $node_id * @property int $key_type * @property string $identifier * @property string $token @@ -104,7 +103,6 @@ class ApiKey extends Model implements HasAbilities protected $casts = [ 'allowed_ips' => 'array', 'user_id' => 'int', - 'node_id' => 'int', 'last_used_at' => 'datetime', 'expires_at' => 'datetime', self::CREATED_AT => 'datetime', @@ -149,7 +147,6 @@ class ApiKey extends Model implements HasAbilities 'memo' => 'required|nullable|string|max:500', 'allowed_ips' => 'nullable|array', 'allowed_ips.*' => 'string', - 'node_id' => 'nullable|exists:nodes,id', 'last_used_at' => 'nullable|date', 'expires_at' => 'nullable|date', 'r_' . AdminAcl::RESOURCE_USERS => 'integer|min:0|max:3', @@ -159,7 +156,7 @@ class ApiKey extends Model implements HasAbilities 'r_' . AdminAcl::RESOURCE_EGGS => 'integer|min:0|max:3', 'r_' . AdminAcl::RESOURCE_LOCATIONS => 'integer|min:0|max:3', 'r_' . AdminAcl::RESOURCE_NESTS => 'integer|min:0|max:3', - 'r_' . AdminAcl::RESOURCE_NODES => 'integer|min:0|max:7', + 'r_' . AdminAcl::RESOURCE_NODES => 'integer|min:0|max:3', 'r_' . AdminAcl::RESOURCE_SERVERS => 'integer|min:0|max:3', ]; diff --git a/app/Services/Acl/Api/AdminAcl.php b/app/Services/Acl/Api/AdminAcl.php index dfb43601c..cee076e17 100644 --- a/app/Services/Acl/Api/AdminAcl.php +++ b/app/Services/Acl/Api/AdminAcl.php @@ -19,7 +19,6 @@ class AdminAcl public const NONE = 0; public const READ = 1; public const WRITE = 2; - public const READ_CONFIGURATION = 4; /** * Resources that are available on the API and can contain a permissions diff --git a/database/migrations/2026_06_23_205500_add_node_id_to_api_keys_table.php b/database/migrations/2026_06_23_205500_add_node_id_to_api_keys_table.php deleted file mode 100644 index 59c1da398..000000000 --- a/database/migrations/2026_06_23_205500_add_node_id_to_api_keys_table.php +++ /dev/null @@ -1,29 +0,0 @@ -unsignedInteger('node_id')->nullable()->after('user_id'); - $table->foreign('node_id')->references('id')->on('nodes')->onDelete('cascade'); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('api_keys', function (Blueprint $table) { - $table->dropForeign(['node_id']); - $table->dropColumn('node_id'); - }); - } -}; diff --git a/database/schema/mysql-schema.sql b/database/schema/mysql-schema.sql index e53a1d5a7..bb03afc28 100644 --- a/database/schema/mysql-schema.sql +++ b/database/schema/mysql-schema.sql @@ -63,7 +63,6 @@ DROP TABLE IF EXISTS `api_keys`; CREATE TABLE `api_keys` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL, - `node_id` int(10) unsigned DEFAULT NULL, `key_type` tinyint(3) unsigned NOT NULL DEFAULT 0, `identifier` char(16) DEFAULT NULL, `token` text NOT NULL, @@ -85,8 +84,6 @@ CREATE TABLE `api_keys` ( PRIMARY KEY (`id`), UNIQUE KEY `api_keys_identifier_unique` (`identifier`), KEY `api_keys_user_id_foreign` (`user_id`), - KEY `api_keys_node_id_foreign` (`node_id`), - CONSTRAINT `api_keys_node_id_foreign` FOREIGN KEY (`node_id`) REFERENCES `nodes` (`id`) ON DELETE CASCADE, CONSTRAINT `api_keys_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -879,4 +876,3 @@ INSERT INTO `migrations` VALUES (191,'2022_08_16_230204_add_installed_at_column_ INSERT INTO `migrations` VALUES (192,'2022_12_12_213937_update_mail_settings_to_new_format',1); INSERT INTO `migrations` VALUES (193,'2023_01_24_210051_add_uuid_column_to_failed_jobs_table',1); INSERT INTO `migrations` VALUES (194,'2023_02_23_191004_add_expires_at_column_to_api_keys_table',1); -INSERT INTO `migrations` VALUES (195,'2026_06_23_205500_add_node_id_to_api_keys_table',1); diff --git a/tests/Integration/Api/Application/Nodes/NodeConfigurationControllerTest.php b/tests/Integration/Api/Application/Nodes/NodeConfigurationControllerTest.php index 180f18779..604f0798d 100644 --- a/tests/Integration/Api/Application/Nodes/NodeConfigurationControllerTest.php +++ b/tests/Integration/Api/Application/Nodes/NodeConfigurationControllerTest.php @@ -9,13 +9,11 @@ use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestC class NodeConfigurationControllerTest extends ApplicationApiIntegrationTestCase { - public function testConfigurationKeyCanGetNodeConfiguration(): void + public function testWriteNodeKeyCanGetNodeConfiguration(): void { + $this->createNewDefaultApiKey($this->getApiUser(), ['r_nodes' => AdminAcl::READ | AdminAcl::WRITE]); + $node = Node::factory()->for(Location::factory())->create(); - $this->createNewDefaultApiKey($this->getApiUser(), [ - 'node_id' => $node->id, - 'r_nodes' => AdminAcl::READ_CONFIGURATION, - ]); $response = $this->getJson('/api/application/nodes/' . $node->id . '/configuration'); @@ -25,27 +23,6 @@ class NodeConfigurationControllerTest extends ApplicationApiIntegrationTestCase $this->assertSame(decrypt($node->daemon_token), $response->json('token')); } - public function testConfigurationKeyCannotGetOtherNodeConfiguration(): void - { - $node = Node::factory()->for(Location::factory())->create(); - $otherNode = Node::factory()->for(Location::factory())->create(); - $this->createNewDefaultApiKey($this->getApiUser(), [ - 'node_id' => $node->id, - 'r_nodes' => AdminAcl::READ_CONFIGURATION, - ]); - - $this->assertAccessDeniedJson($this->getJson('/api/application/nodes/' . $otherNode->id . '/configuration')); - } - - public function testWriteKeyCanGetNodeConfiguration(): void - { - $this->createNewDefaultApiKey($this->getApiUser(), ['r_nodes' => AdminAcl::WRITE]); - - $node = Node::factory()->for(Location::factory())->create(); - - $this->getJson('/api/application/nodes/' . $node->id . '/configuration')->assertOk(); - } - public function testReadOnlyNodeKeyCannotGetNodeConfiguration(): void { $this->createNewDefaultApiKey($this->getApiUser(), ['r_nodes' => AdminAcl::READ]); @@ -54,15 +31,4 @@ class NodeConfigurationControllerTest extends ApplicationApiIntegrationTestCase $this->assertAccessDeniedJson($this->getJson('/api/application/nodes/' . $node->id . '/configuration')); } - - public function testConfigurationKeyCannotUpdateNode(): void - { - $node = Node::factory()->for(Location::factory())->create(); - $this->createNewDefaultApiKey($this->getApiUser(), [ - 'node_id' => $node->id, - 'r_nodes' => AdminAcl::READ_CONFIGURATION, - ]); - - $this->assertAccessDeniedJson($this->patchJson(route('api.application.nodes.update', ['node' => $node]))); - } } diff --git a/tests/Integration/Http/Controllers/Admin/NodeAutoDeployControllerTest.php b/tests/Integration/Http/Controllers/Admin/NodeAutoDeployControllerTest.php index fd6e926b5..997b34d04 100644 --- a/tests/Integration/Http/Controllers/Admin/NodeAutoDeployControllerTest.php +++ b/tests/Integration/Http/Controllers/Admin/NodeAutoDeployControllerTest.php @@ -11,7 +11,7 @@ use Pterodactyl\Tests\Integration\Http\HttpTestCase; class NodeAutoDeployControllerTest extends HttpTestCase { - public function testGeneratedTokenIsScopedToNodeConfiguration(): void + public function testGeneratedTokenHasNodeWritePermission(): void { $node = Node::factory()->for(Location::factory())->create(); @@ -25,7 +25,6 @@ class NodeAutoDeployControllerTest extends HttpTestCase ->where('identifier', substr($response->json('token'), 0, ApiKey::IDENTIFIER_LENGTH)) ->firstOrFail(); - $this->assertSame($node->id, $key->node_id); - $this->assertSame(AdminAcl::READ_CONFIGURATION, $key->r_nodes); + $this->assertSame(AdminAcl::READ | AdminAcl::WRITE, $key->r_nodes); } }