[PR #1702] [MERGED] feat(apikey): adds command to delete api keys #2265

Closed
opened 2025-12-29 03:20:28 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/1702
Author: @pallabpain
Created: 1/27/2024
Status: Merged
Merged: 2/12/2024
Merged by: @kradalby

Base: mainHead: feat/delete-apikeys


📝 Commits (1)

  • 8e217a8 feat: adds command to delete api keys

📊 Changes

16 files changed (+543 additions, -163 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 cmd/headscale/cli/api_key.go (+51 -4)
📝 gen/go/headscale/v1/apikey.pb.go (+127 -12)
📝 gen/go/headscale/v1/device.pb.go (+1 -1)
📝 gen/go/headscale/v1/headscale.pb.go (+70 -58)
📝 gen/go/headscale/v1/headscale.pb.gw.go (+103 -0)
📝 gen/go/headscale/v1/headscale_grpc.pb.go (+87 -79)
📝 gen/go/headscale/v1/node.pb.go (+1 -1)
📝 gen/go/headscale/v1/preauthkey.pb.go (+1 -1)
📝 gen/go/headscale/v1/routes.pb.go (+1 -1)
📝 gen/go/headscale/v1/user.pb.go (+1 -1)
📝 gen/openapiv2/headscale/v1/headscale.swagger.json (+33 -0)
📝 hscontrol/grpcv1.go (+26 -4)
📝 integration/cli_test.go (+27 -1)
📝 proto/headscale/v1/apikey.proto (+7 -0)
📝 proto/headscale/v1/headscale.proto (+6 -0)

📄 Description

Description

We currently do not have a way to clean up api keys. There may be cases where users of headscale may generate a lot of api keys and these may end up accumulating in the database. This commit adds the command to delete an api key given a prefix.

Usage

→ hs apikeys --help
Handle the Api keys in Headscale

Usage:
  headscale apikeys [command]

Aliases:
  apikeys, apikey, api

Available Commands:
  create      Creates a new Api key
  delete      Delete an ApiKey
  expire      Expire an ApiKey
  list        List the Api keys for headscale

Flags:
  -h, --help   help for apikeys

Global Flags:
  -c, --config string   config file (default is /etc/headscale/config.yaml)
      --force           Disable prompts and forces the execution
  -o, --output string   Output format. Empty for human-readable, 'json', 'json-line' or 'yaml'

Use "headscale apikeys [command] --help" for more information about a command.

→ hs apikeys delete --help
Delete an ApiKey

Usage:
  headscale apikeys delete [flags]

Aliases:
  delete, remove, del

Flags:
  -h, --help            help for delete
  -p, --prefix string   ApiKey prefix

Global Flags:
  -c, --config string   config file (default is /etc/headscale/config.yaml)
      --force           Disable prompts and forces the execution
  -o, --output string   Output format. Empty for human-readable, 'json', 'json-line' or 'yaml'

Testing

Manual

04:16:58 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ sudo ./headscale apikeys create -e 9d --config config.yaml
uYZ927_pGw.2BjBph-ncqd5ZFM1_cISVgjEUkHA8fj-vOYn3WuaZ3Y

04:17:06 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ sudo ./headscale apikeys ls --config config.yaml 
ID | Prefix     | Expiration          | Created
1  | uYZ927_pGw | 2024-02-06 10:47:06 | 2024-01-28 10:47:06

04:17:09 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ alias hs='sudo ./headscale --config config.yaml'

04:17:39 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ hs apikeys ls
ID | Prefix     | Expiration          | Created
1  | uYZ927_pGw | 2024-02-06 10:47:06 | 2024-01-28 10:47:06

04:17:44 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ hs apikeys delete --prefix uYZ927_pGw
Key deleted

04:17:54 pallab@pop-os headscale ±|feat/delete-apikeys ✗|
→ hs apikeys ls
ID | Prefix | Expiration | Created
  • read the CONTRIBUTING guidelines
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md

Resolves

Depends


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/juanfont/headscale/pull/1702 **Author:** [@pallabpain](https://github.com/pallabpain) **Created:** 1/27/2024 **Status:** ✅ Merged **Merged:** 2/12/2024 **Merged by:** [@kradalby](https://github.com/kradalby) **Base:** `main` ← **Head:** `feat/delete-apikeys` --- ### 📝 Commits (1) - [`8e217a8`](https://github.com/juanfont/headscale/commit/8e217a8f3a0c8c2947f9af56859b3df3cbda2987) feat: adds command to delete api keys ### 📊 Changes **16 files changed** (+543 additions, -163 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `cmd/headscale/cli/api_key.go` (+51 -4) 📝 `gen/go/headscale/v1/apikey.pb.go` (+127 -12) 📝 `gen/go/headscale/v1/device.pb.go` (+1 -1) 📝 `gen/go/headscale/v1/headscale.pb.go` (+70 -58) 📝 `gen/go/headscale/v1/headscale.pb.gw.go` (+103 -0) 📝 `gen/go/headscale/v1/headscale_grpc.pb.go` (+87 -79) 📝 `gen/go/headscale/v1/node.pb.go` (+1 -1) 📝 `gen/go/headscale/v1/preauthkey.pb.go` (+1 -1) 📝 `gen/go/headscale/v1/routes.pb.go` (+1 -1) 📝 `gen/go/headscale/v1/user.pb.go` (+1 -1) 📝 `gen/openapiv2/headscale/v1/headscale.swagger.json` (+33 -0) 📝 `hscontrol/grpcv1.go` (+26 -4) 📝 `integration/cli_test.go` (+27 -1) 📝 `proto/headscale/v1/apikey.proto` (+7 -0) 📝 `proto/headscale/v1/headscale.proto` (+6 -0) </details> ### 📄 Description ### Description We currently do not have a way to clean up api keys. There may be cases where users of headscale may generate a lot of api keys and these may end up accumulating in the database. This commit adds the command to delete an api key given a prefix. ### Usage ``` → hs apikeys --help Handle the Api keys in Headscale Usage: headscale apikeys [command] Aliases: apikeys, apikey, api Available Commands: create Creates a new Api key delete Delete an ApiKey expire Expire an ApiKey list List the Api keys for headscale Flags: -h, --help help for apikeys Global Flags: -c, --config string config file (default is /etc/headscale/config.yaml) --force Disable prompts and forces the execution -o, --output string Output format. Empty for human-readable, 'json', 'json-line' or 'yaml' Use "headscale apikeys [command] --help" for more information about a command. → hs apikeys delete --help Delete an ApiKey Usage: headscale apikeys delete [flags] Aliases: delete, remove, del Flags: -h, --help help for delete -p, --prefix string ApiKey prefix Global Flags: -c, --config string config file (default is /etc/headscale/config.yaml) --force Disable prompts and forces the execution -o, --output string Output format. Empty for human-readable, 'json', 'json-line' or 'yaml' ``` ### Testing #### Manual ``` 04:16:58 pallab@pop-os headscale ±|feat/delete-apikeys ✗| → sudo ./headscale apikeys create -e 9d --config config.yaml uYZ927_pGw.2BjBph-ncqd5ZFM1_cISVgjEUkHA8fj-vOYn3WuaZ3Y 04:17:06 pallab@pop-os headscale ±|feat/delete-apikeys ✗| → sudo ./headscale apikeys ls --config config.yaml ID | Prefix | Expiration | Created 1 | uYZ927_pGw | 2024-02-06 10:47:06 | 2024-01-28 10:47:06 04:17:09 pallab@pop-os headscale ±|feat/delete-apikeys ✗| → alias hs='sudo ./headscale --config config.yaml' 04:17:39 pallab@pop-os headscale ±|feat/delete-apikeys ✗| → hs apikeys ls ID | Prefix | Expiration | Created 1 | uYZ927_pGw | 2024-02-06 10:47:06 | 2024-01-28 10:47:06 04:17:44 pallab@pop-os headscale ±|feat/delete-apikeys ✗| → hs apikeys delete --prefix uYZ927_pGw Key deleted 04:17:54 pallab@pop-os headscale ±|feat/delete-apikeys ✗| → hs apikeys ls ID | Prefix | Expiration | Created ``` - [x] read the [CONTRIBUTING guidelines](README.md#contributing) - [x] raised a GitHub issue or discussed it on the projects chat beforehand - [x] added unit tests - [x] added integration tests - [x] updated documentation if needed - [x] updated CHANGELOG.md <!-- If applicable, please reference the issue using `Fixes #XXX` and add tests to cover your new code. --> ### Resolves - https://github.com/juanfont/headscale/issues/1667 ### Depends - https://github.com/juanfont/headscale/pull/1701 - https://github.com/juanfont/headscale/pull/1700 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 03:20:28 +01:00
adam closed this issue 2025-12-29 03:20:29 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#2265