-
Notifications
You must be signed in to change notification settings - Fork 840
Allow the creation of API-only users #43440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
juan-fdz-hawa
merged 18 commits into
main
from
42882_42880_42884_allow_creation_of_api_only_users
Apr 16, 2026
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a7ff10b
Allow the creation of API-only users
juan-fdz-hawa 3ace46c
Regen schema
juan-fdz-hawa ec76cad
Fixed test
juan-fdz-hawa 8b3360f
PR feedback
juan-fdz-hawa fa1415c
No not return 403 if user not found
juan-fdz-hawa 9b72dbd
Refactored tests
juan-fdz-hawa 15f3e7e
Add limits to the number of api_endpoints we can send
juan-fdz-hawa 3799268
Add missing checks
juan-fdz-hawa f61916e
Make sure non-API users can be changed to be API-only users and vicev…
juan-fdz-hawa 5edd9cf
Added missing test
juan-fdz-hawa bfd330f
PR feedback
juan-fdz-hawa 2e05036
Preserve current API behavior
juan-fdz-hawa 6687288
Return more generic error
juan-fdz-hawa 02da70e
Remove wildcard rule
juan-fdz-hawa 4bef2fa
Fixed linter issues and some PR feedback
juan-fdz-hawa a728b2d
Remove not needed migration
juan-fdz-hawa 10caf68
PR feedback
juan-fdz-hawa c2af1e2
Fixed issues with serialization
juan-fdz-hawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| - Added POST /users/api_only endpoint for creating API-only users. | ||
| - Added PATCH /users/api_only/{id} for updating existing API-only users. | ||
| - Updated GET /users/{id} response to include the new `api_endpoints` field for API-only users. | ||
| - Updated `fleetctl user create --api-only` removing email/password field requirements. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
server/datastore/mysql/migrations/tables/20260411000000_DropAuthorIdFromUserApiEndpoints.go
|
lucasmrod marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package tables | ||
|
|
||
| import ( | ||
| "database/sql" | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| func init() { | ||
| MigrationClient.AddMigration(Up_20260411000000, Down_20260411000000) | ||
| } | ||
|
|
||
| func Up_20260411000000(tx *sql.Tx) error { | ||
| // Find the foreign key constraint name for the author_id column specifically. | ||
| var constraintName string | ||
| err := tx.QueryRow(` | ||
| SELECT CONSTRAINT_NAME | ||
| FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE | ||
| WHERE TABLE_NAME = 'user_api_endpoints' | ||
| AND COLUMN_NAME = 'author_id' | ||
| AND CONSTRAINT_SCHEMA = DATABASE() | ||
| AND REFERENCED_TABLE_NAME = 'users' | ||
| `).Scan(&constraintName) | ||
| if err != nil && err != sql.ErrNoRows { | ||
| return fmt.Errorf("look up author_id foreign key: %w", err) | ||
| } | ||
|
|
||
| if constraintName != "" { | ||
| escaped := strings.ReplaceAll(constraintName, "`", "``") | ||
| if _, err := tx.Exec(fmt.Sprintf( | ||
| "ALTER TABLE user_api_endpoints DROP FOREIGN KEY `%s`", escaped, | ||
| )); err != nil { | ||
| return fmt.Errorf("drop author_id foreign key: %w", err) | ||
| } | ||
| } | ||
|
|
||
| _, err = tx.Exec(`ALTER TABLE user_api_endpoints DROP COLUMN author_id`) | ||
|
juan-fdz-hawa marked this conversation as resolved.
Outdated
|
||
| return err | ||
| } | ||
|
|
||
| func Down_20260411000000(tx *sql.Tx) error { | ||
| return nil | ||
| } | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.