diff --git a/proto/headscale/v1/device.proto b/proto/headscale/v1/device.proto new file mode 100644 index 00000000..207ff374 --- /dev/null +++ b/proto/headscale/v1/device.proto @@ -0,0 +1,83 @@ +syntax = "proto3"; +package headscale.v1; +option go_package = "github.com/juanfont/headscale/gen/go/v1"; + +import "google/protobuf/timestamp.proto"; + +// This is a potential reimplementation of Tailscale's API +// https://github.com/tailscale/tailscale/blob/main/api.md + +message Latency { + float latency_ms = 1; + bool preferred = 2; +} + +message ClientSupports { + bool hair_pinning = 1; + bool ipv6 = 2; + bool pcp = 3; + bool pmp = 4; + bool udp = 5; + bool upnp = 6; +} + +message ClientConnectivity { + repeated string endpoints = 1; + string derp = 2; + bool mapping_varies_by_dest_ip = 3; + map latency = 4; + ClientSupports client_supports = 5; +} + +message GetDeviceRequest { + string id = 1; +} + +message GetDeviceResponse { + repeated string addresses = 1; + string id = 2; + string user = 3; + string name = 4; + string hostname = 5; + string client_version = 6; + bool update_available = 7; + string os = 8; + google.protobuf.Timestamp created = 9; + google.protobuf.Timestamp last_seen = 10; + bool key_expiry_disabled = 11; + google.protobuf.Timestamp expires = 12; + bool authorized = 13; + bool is_external = 14; + string machine_key = 15; + string node_key = 16; + bool blocks_incoming_connections = 17; + repeated string enabled_routes = 18; + repeated string advertised_routes = 19; + ClientConnectivity client_connectivity = 20; +} + +message DeleteDeviceRequest { + string id = 1; +} + +message DeleteDeviceResponse { +} + +message GetDeviceRoutesRequest { + string id = 1; +} + +message GetDeviceRoutesResponse { + repeated string enabled_routes = 1; + repeated string advertised_routes = 2; +} + +message EnableDeviceRoutesRequest { + string id = 1; + repeated string routes = 2; +} + +message EnableDeviceRoutesResponse { + repeated string enabled_routes = 1; + repeated string advertised_routes = 2; +} diff --git a/proto/headscale/v1/headscale.proto b/proto/headscale/v1/headscale.proto index 2e6b0a67..26fe2f96 100644 --- a/proto/headscale/v1/headscale.proto +++ b/proto/headscale/v1/headscale.proto @@ -2,86 +2,19 @@ syntax = "proto3"; package headscale.v1; option go_package = "github.com/juanfont/headscale/gen/go/v1"; -import "google/protobuf/timestamp.proto"; import "google/api/annotations.proto"; -enum RegisterMethod { - REGISTER_METHOD_UNSPECIFIED = 0; - REGISTER_METHOD_AUTH_KEY = 1; - REGISTER_METHOD_CLI = 2; - REGISTER_METHOD_OIDC = 3; -} - -// message PreAuthKey { -// uint64 id = 1; -// string key = 2; -// uint32 namespace_id = 3; -// Namespace namespace = 4; -// bool reusable = 5; -// bool ephemeral = 6; -// bool used = 7; -// -// google.protobuf.Timestamp created_at = 8; -// google.protobuf.Timestamp expiration = 9; -// } - -message GetMachineRequest { - uint64 machine_id = 1; -} - -message GetMachineResponse { - uint64 id = 1; - string machine_key = 2; - string node_key = 3; - string disco_key = 4; - string ip_address = 5; - string name = 6; - uint32 namespace_id = 7; - - bool registered = 8; - RegisterMethod register_method = 9; - uint32 auth_key_id = 10; - // PreAuthKey auth_key = 11; - - google.protobuf.Timestamp last_seen = 12; - google.protobuf.Timestamp last_successful_update = 13; - google.protobuf.Timestamp expiry = 14; - - // bytes host_info = 15; - // bytes endpoints = 16; - // bytes enabled_routes = 17; - - // google.protobuf.Timestamp created_at = 18; - // google.protobuf.Timestamp updated_at = 19; - // google.protobuf.Timestamp deleted_at = 20; -} - -message CreateNamespaceRequest { - string name = 1; -} - -message CreateNamespaceResponse { - string name = 1; -} - -message DeleteNamespaceRequest { - string name = 1; -} - -message DeleteNamespaceResponse { -} - -message ListNamespacesRequest { -} - -message ListNamespacesResponse { - repeated string namespaces = 1; -} +import "headscale/v1/namespace.proto"; +import "headscale/v1/preauthkey.proto"; +import "headscale/v1/machine.proto"; +import "headscale/v1/routes.proto"; +// import "headscale/v1/device.proto"; service HeadscaleService { - rpc GetMachine(GetMachineRequest) returns(GetMachineResponse) { + // --- Namespace start --- + rpc GetNamespace(GetNamespaceRequest) returns(GetNamespaceResponse) { option(google.api.http) = { - get : "/api/v1/machine/{machine_id}" + get : "/api/v1/namespace/{name}" }; } @@ -92,9 +25,15 @@ service HeadscaleService { }; } + rpc RenameNamespace(RenameNamespaceRequest) returns(RenameNamespaceResponse) { + option(google.api.http) = { + post : "/api/v1/namespace/{old_name}/rename/{new_name}" + }; + } + rpc DeleteNamespace(DeleteNamespaceRequest) returns(DeleteNamespaceResponse) { option(google.api.http) = { - delete : "/api/v1/namespace" + delete : "/api/v1/namespace/{name}" }; } @@ -103,4 +42,111 @@ service HeadscaleService { get : "/api/v1/namespace" }; } + // --- Namespace end --- + + // --- PreAuthKeys start --- + rpc CreatePreAuthKey(CreatePreAuthKeyRequest) returns(CreatePreAuthKeyResponse) { + option(google.api.http) = { + post : "/api/v1/preauthkey" + body : "*" + }; + } + + rpc ExpirePreAuthKey(ExpirePreAuthKeyRequest) returns(ExpirePreAuthKeyResponse) { + option(google.api.http) = { + post : "/api/v1/preauthkey/expire" + body : "*" + }; + } + + rpc ListPreAuthKeys(ListPreAuthKeysRequest) returns(ListPreAuthKeysResponse) { + option(google.api.http) = { + get : "/api/v1/preauthkey" + }; + } + // --- PreAuthKeys end --- + + // --- Machine start --- + rpc DebugCreateMachine(DebugCreateMachineRequest) returns(DebugCreateMachineResponse) { + option(google.api.http) = { + post : "/api/v1/debug/machine" + body : "*" + }; + } + + rpc GetMachine(GetMachineRequest) returns(GetMachineResponse) { + option(google.api.http) = { + get : "/api/v1/machine/{machine_id}" + }; + } + + rpc RegisterMachine(RegisterMachineRequest) returns(RegisterMachineResponse) { + option(google.api.http) = { + post : "/api/v1/machine/register" + }; + } + + rpc DeleteMachine(DeleteMachineRequest) returns(DeleteMachineResponse) { + option(google.api.http) = { + delete : "/api/v1/machine/{machine_id}" + }; + } + + rpc ListMachines(ListMachinesRequest) returns(ListMachinesResponse) { + option(google.api.http) = { + get : "/api/v1/machine" + }; + } + + rpc ShareMachine(ShareMachineRequest) returns(ShareMachineResponse) { + option(google.api.http) = { + post : "/api/v1/machine/{machine_id}/share/{namespace}" + }; + } + + rpc UnshareMachine(UnshareMachineRequest) returns(UnshareMachineResponse) { + option(google.api.http) = { + post : "/api/v1/machine/{machine_id}/unshare/{namespace}" + }; + } + // --- Machine end --- + + // --- Route start --- + rpc GetMachineRoute(GetMachineRouteRequest) returns(GetMachineRouteResponse) { + option(google.api.http) = { + get : "/api/v1/machine/{machine_id}/routes" + }; + } + + rpc EnableMachineRoutes(EnableMachineRoutesRequest) returns(EnableMachineRoutesResponse) { + option(google.api.http) = { + post : "/api/v1/machine/{machine_id}/routes" + }; + } + // --- Route end --- + + // Implement Tailscale API + // rpc GetDevice(GetDeviceRequest) returns(GetDeviceResponse) { + // option(google.api.http) = { + // get : "/api/v1/device/{id}" + // }; + // } + + // rpc DeleteDevice(DeleteDeviceRequest) returns(DeleteDeviceResponse) { + // option(google.api.http) = { + // delete : "/api/v1/device/{id}" + // }; + // } + + // rpc GetDeviceRoutes(GetDeviceRoutesRequest) returns(GetDeviceRoutesResponse) { + // option(google.api.http) = { + // get : "/api/v1/device/{id}/routes" + // }; + // } + + // rpc EnableDeviceRoutes(EnableDeviceRoutesRequest) returns(EnableDeviceRoutesResponse) { + // option(google.api.http) = { + // post : "/api/v1/device/{id}/routes" + // }; + // } } diff --git a/proto/headscale/v1/machine.proto b/proto/headscale/v1/machine.proto new file mode 100644 index 00000000..4e53c4ad --- /dev/null +++ b/proto/headscale/v1/machine.proto @@ -0,0 +1,102 @@ +syntax = "proto3"; +package headscale.v1; +option go_package = "github.com/juanfont/headscale/gen/go/v1"; + +import "google/protobuf/timestamp.proto"; +import "headscale/v1/namespace.proto"; +import "headscale/v1/preauthkey.proto"; + +enum RegisterMethod { + REGISTER_METHOD_UNSPECIFIED = 0; + REGISTER_METHOD_AUTH_KEY = 1; + REGISTER_METHOD_CLI = 2; + REGISTER_METHOD_OIDC = 3; +} + +message Machine { + uint64 id = 1; + string machine_key = 2; + string node_key = 3; + string disco_key = 4; + string ip_address = 5; + string name = 6; + Namespace namespace = 7; + + bool registered = 8; + RegisterMethod register_method = 9; + + google.protobuf.Timestamp last_seen = 10; + google.protobuf.Timestamp last_successful_update = 11; + google.protobuf.Timestamp expiry = 12; + + PreAuthKey pre_auth_key = 13; + + google.protobuf.Timestamp created_at = 14; + // google.protobuf.Timestamp updated_at = 14; + // google.protobuf.Timestamp deleted_at = 15; + + // bytes host_info = 15; + // bytes endpoints = 16; + // bytes enabled_routes = 17; +} + +message RegisterMachineRequest { + string namespace = 1; + string key = 2; +} + +message RegisterMachineResponse { + Machine machine = 1; +} + +message GetMachineRequest { + uint64 machine_id = 1; +} + +message GetMachineResponse { + Machine machine = 1; +} + +message DeleteMachineRequest { + uint64 machine_id = 1; +} + +message DeleteMachineResponse { +} + +message ListMachinesRequest { + string namespace = 1; +} + +message ListMachinesResponse { + repeated Machine machines = 1; +} + +message ShareMachineRequest { + uint64 machine_id = 1; + string namespace = 2; +} + +message ShareMachineResponse { + Machine machine = 1; +} + +message UnshareMachineRequest { + uint64 machine_id = 1; + string namespace = 2; +} + +message UnshareMachineResponse { + Machine machine = 1; +} + +message DebugCreateMachineRequest { + string namespace = 1; + string key = 2; + string name = 3; + repeated string routes = 4; +} + +message DebugCreateMachineResponse { + Machine machine = 1; +} diff --git a/proto/headscale/v1/namespace.proto b/proto/headscale/v1/namespace.proto new file mode 100644 index 00000000..997b74c3 --- /dev/null +++ b/proto/headscale/v1/namespace.proto @@ -0,0 +1,50 @@ +syntax = "proto3"; +package headscale.v1; +option go_package = "github.com/juanfont/headscale/gen/go/v1"; + +import "google/protobuf/timestamp.proto"; + +message Namespace { + string id = 1; + string name = 2; + google.protobuf.Timestamp created_at = 3; +} + +message GetNamespaceRequest { + string name = 1; +} + +message GetNamespaceResponse { + Namespace namespace = 1; +} + +message CreateNamespaceRequest { + string name = 1; +} + +message CreateNamespaceResponse { + Namespace namespace = 1; +} + +message RenameNamespaceRequest { + string old_name = 1; + string new_name = 2; +} + +message RenameNamespaceResponse { + Namespace namespace = 1; +} + +message DeleteNamespaceRequest { + string name = 1; +} + +message DeleteNamespaceResponse { +} + +message ListNamespacesRequest { +} + +message ListNamespacesResponse { + repeated Namespace namespaces = 1; +} diff --git a/proto/headscale/v1/preauthkey.proto b/proto/headscale/v1/preauthkey.proto new file mode 100644 index 00000000..195c3215 --- /dev/null +++ b/proto/headscale/v1/preauthkey.proto @@ -0,0 +1,43 @@ +syntax = "proto3"; +package headscale.v1; +option go_package = "github.com/juanfont/headscale/gen/go/v1"; + +import "google/protobuf/timestamp.proto"; + +message PreAuthKey { + string namespace = 1; + string id = 2; + string key = 3; + bool resuable = 4; + bool ephemeral = 5; + bool used = 6; + google.protobuf.Timestamp expiration = 7; + google.protobuf.Timestamp created_at = 8; +} + +message CreatePreAuthKeyRequest { + string namespace = 1; + bool resuable = 2; + bool ephemeral = 3; + google.protobuf.Timestamp expiration = 4; +} + +message CreatePreAuthKeyResponse { + PreAuthKey pre_auth_key = 1; +} + +message ExpirePreAuthKeyRequest { + string namespace = 1; + string key = 2; +} + +message ExpirePreAuthKeyResponse { +} + +message ListPreAuthKeysRequest { + string namespace = 1; +} + +message ListPreAuthKeysResponse { + repeated PreAuthKey pre_auth_keys = 1; +} diff --git a/proto/headscale/v1/routes.proto b/proto/headscale/v1/routes.proto new file mode 100644 index 00000000..353c4294 --- /dev/null +++ b/proto/headscale/v1/routes.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; +package headscale.v1; +option go_package = "github.com/juanfont/headscale/gen/go/v1"; + +message Routes { + repeated string advertised_routes = 1; + repeated string enabled_routes = 2; +} + +message GetMachineRouteRequest { + uint64 machine_id = 1; +} + +message GetMachineRouteResponse { + Routes routes = 1; +} + +message EnableMachineRoutesRequest { + uint64 machine_id = 1; + repeated string routes = 2; +} + +message EnableMachineRoutesResponse { + Routes routes = 1; +}