core -> metropolis
Smalltown is now called Metropolis!
This is the first commit in a series of cleanup commits that prepare us
for an open source release. This one just some Bazel packages around to
follow a stricter directory layout.
All of Metropolis now lives in `//metropolis`.
All of Metropolis Node code now lives in `//metropolis/node`.
All of the main /init now lives in `//m/n/core`.
All of the Kubernetes functionality/glue now lives in `//m/n/kubernetes`.
Next steps:
- hunt down all references to Smalltown and replace them appropriately
- narrow down visibility rules
- document new code organization
- move `//build/toolchain` to `//monogon/build/toolchain`
- do another cleanup pass between `//golibs` and
`//monogon/node/{core,common}`.
- remove `//delta` and `//anubis`
Fixes T799.
Test Plan: Just a very large refactor. CI should help us out here.
Bug: T799
X-Origin-Diff: phab/D667
GitOrigin-RevId: 6029b8d4edc42325d50042596b639e8b122d0ded
diff --git a/metropolis/proto/api/BUILD.bazel b/metropolis/proto/api/BUILD.bazel
new file mode 100644
index 0000000..ec40562
--- /dev/null
+++ b/metropolis/proto/api/BUILD.bazel
@@ -0,0 +1,27 @@
+load("@rules_proto//proto:defs.bzl", "proto_library")
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
+
+proto_library(
+ name = "api_proto",
+ srcs = [
+ "debug.proto",
+ "enrolment.proto",
+ ],
+ visibility = ["//visibility:public"],
+)
+
+go_proto_library(
+ name = "api_go_proto",
+ compilers = ["@io_bazel_rules_go//proto:go_grpc"],
+ importpath = "git.monogon.dev/source/nexantic.git/metropolis/proto/api",
+ proto = ":api_proto",
+ visibility = ["//visibility:public"],
+)
+
+go_library(
+ name = "go_default_library",
+ embed = [":api_go_proto"],
+ importpath = "git.monogon.dev/source/nexantic.git/metropolis/proto/api",
+ visibility = ["//visibility:public"],
+)
diff --git a/metropolis/proto/api/debug.proto b/metropolis/proto/api/debug.proto
new file mode 100644
index 0000000..2483360
--- /dev/null
+++ b/metropolis/proto/api/debug.proto
@@ -0,0 +1,164 @@
+// Copyright 2020 The Monogon Project Authors.
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+syntax = "proto3";
+package smalltown.core.proto.api;
+option go_package = "git.monogon.dev/source/nexantic.git/metropolis/proto/api";
+
+import "metropolis/proto/api/enrolment.proto";
+
+// NodeDebugService exposes debug and testing endpoints that allow introspection into a running Smalltown instance.
+// It is not authenticated and will be disabled in production. It is currently consumed by metropolis/cli/dbg and
+// by tests.
+service NodeDebugService {
+ // GetDebugKubeconfig issues kubeconfigs with arbitrary identities and groups for debugging
+ rpc GetDebugKubeconfig(GetDebugKubeconfigRequest) returns (GetDebugKubeconfigResponse);
+
+ // GetLogs Returns historical and/or streaming logs for a given DN with given filters from the system global
+ // LogTree.
+ //
+ // For more information about this API, see //metropolis/node/core/logtree. But, in summary:
+ // - All logging is performed to a DN (distinguished name), which is a dot-delimited string like foo.bar.baz.
+ // - Log entries can be either raw (coming from unstructured logging from an external service, like a running
+ // process) or leveled (emitted by Smalltown code with a source line, timestamp, and severity).
+ // - The DNs form a tree of logging nodes - and when requesting logs, a given subtree of DNs can be requested,
+ // instead of just a given DN.
+ // - All supervised processes live at `root.<supervisor DN>`. For more example paths, see the console logs of
+ // a running Smalltown instance, or request all logs (at DN "").
+ //
+ // TODO(q3k): move method and its related messages to the non-debug node endpoint once we have one.
+ rpc GetLogs(GetLogsRequest) returns (stream GetLogsResponse);
+
+ // GetGoldenTicket requests a 'golden ticket' which can be used to enroll any node into the cluster.
+ // This bypasses integrity checks.
+ rpc GetGoldenTicket(GetGoldenTicketRequest) returns (GetGoldenTicketResponse);
+}
+
+
+message GetDebugKubeconfigRequest {
+ string id = 1; // Kubernetes identity (user)
+ repeated string groups = 2; // Kubernetes groups
+}
+
+message GetDebugKubeconfigResponse {
+ string debug_kubeconfig = 1;
+}
+
+// Severity level corresponding to //metropolis/node/core/logtree.Severity.
+enum LeveledLogSeverity {
+ INVALID = 0;
+ INFO = 1;
+ WARNING = 2;
+ ERROR = 3;
+ FATAL = 4;
+}
+
+// Filter set when requesting logs for a given DN. This message is equivalent to the following GADT enum:
+// data LogFilter = WithChildren
+// | OnlyRaw
+// | OnlyLeveled
+// | LeveledWithMinimumSeverity(Severity)
+//
+// Multiple LogFilters can be chained/combined when requesting logs, as long as they do not conflict.
+message LogFilter {
+ // Entries will be returned not only for the given DN, but all child DNs as well. For instance, if the
+ // requested DN is foo, entries logged to foo, foo.bar and foo.bar.baz will all be returned.
+ message WithChildren {
+ }
+ // Only raw logging entries will be returned. Conflicts with OnlyLeveled filters.
+ message OnlyRaw {
+ }
+ // Only leveled logging entries will be returned. Conflicts with OnlyRaw filters.
+ message OnlyLeveled {
+ }
+ // If leveled logs are returned, all entries at severity lower than `minimum` will be discarded.
+ message LeveledWithMinimumSeverity {
+ LeveledLogSeverity minimum = 1;
+ }
+ oneof filter {
+ WithChildren with_children = 1;
+ OnlyRaw only_raw = 3;
+ OnlyLeveled only_leveled = 4;
+ LeveledWithMinimumSeverity leveled_with_minimum_severity = 5;
+ }
+}
+
+message GetLogsRequest {
+ // DN from which to request logs. All supervised runnables live at `root.`, the init code lives at `init.`.
+ string dn = 1;
+ // Filters to apply to returned data.
+ repeated LogFilter filters = 2;
+
+ enum BacklogMode {
+ BACKLOG_INVALID = 0;
+ // No historic data will be returned.
+ BACKLOG_DISABLE = 1;
+ // All available historic data will be returned.
+ BACKLOG_ALL = 2;
+ // At most backlog_count entries will be returned, if available.
+ BACKLOG_COUNT = 3;
+ }
+ BacklogMode backlog_mode = 3;
+ int64 backlog_count = 4;
+
+ enum StreamMode {
+ STREAM_INVALID = 0;
+ // No streaming entries, gRPC stream will be closed as soon as all backlog data is served.
+ STREAM_DISABLE = 1;
+ // Entries will be streamed as early as available right after all backlog data is served.
+ STREAM_UNBUFFERED = 2;
+ }
+ StreamMode stream_mode = 5;
+}
+
+message GetLogsResponse {
+ // Entries from the requested historical entries (via WithBackLog). They will all be served before the first
+ // stream_entries are served (if any).
+ repeated LogEntry backlog_entries = 1;
+ // Entries streamed as they arrive. Currently no server-side buffering is enabled, instead every line is served
+ // as early as it arrives. However, this might change in the future, so this behaviour cannot be depended
+ // upon.
+ repeated LogEntry stream_entries = 2;
+}
+
+message LogEntry {
+ message Leveled {
+ repeated string lines = 1;
+ int64 timestamp = 2;
+ LeveledLogSeverity severity = 3;
+ string location = 4;
+ }
+ message Raw {
+ string data = 1;
+ int64 original_length = 2;
+ }
+
+ string dn = 1;
+ oneof kind {
+ Leveled leveled = 2;
+ Raw raw = 3;
+ }
+}
+
+message GetGoldenTicketRequest {
+ // IP address at which the new node will run.
+ string external_ip = 1;
+}
+
+message GetGoldenTicketResponse {
+ // Ticket to use in the new node's EnrolmentConfig.
+ GoldenTicket ticket = 1;
+}
diff --git a/metropolis/proto/api/enrolment.proto b/metropolis/proto/api/enrolment.proto
new file mode 100644
index 0000000..c07e4ea
--- /dev/null
+++ b/metropolis/proto/api/enrolment.proto
@@ -0,0 +1,63 @@
+// Copyright 2020 The Monogon Project Authors.
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+syntax = "proto3";
+package smalltown.core.proto.api;
+option go_package = "git.monogon.dev/source/nexantic.git/metropolis/proto/api";
+
+// EnrolmentConfig is the single boot configuration file contained in the Smalltown ESP. It configures
+// the way the node will start up (what cluster it will join/enroll into/create).
+message EnrolmentConfig {
+ // Debug/temporary cluster enrolment method. If set, the node will attempt to enroll into the
+ // cluster that this ticket was generated for. Otherwise, a new cluster will be created.
+ GoldenTicket golden_ticket = 1;
+
+ // Filled in by node after it is enrolled
+ string node_id = 2;
+}
+
+// GoldenTicket is a ticket that allows any node to enroll into a cluster, bypassing any integrity
+// checks.
+//
+// Currently, enrolling into a cluster does not use a TPM-based workflow, and instead
+// bases on a simplified workflow of joining consensus by being started with a
+// TLS client certificate. This is a short-circuit fix to allow multi-node
+// clusters for testing before we design the final cluster node lifecycle system.
+message GoldenTicket {
+ // Etcd peer CA certificate.
+ bytes etcd_ca_cert = 1;
+ // Etcd peer client certificate.
+ bytes etcd_client_cert = 2;
+ // Etcd peer client key.
+ bytes etcd_client_key = 3;
+ // Initial etcd peer CRL.
+ bytes etcd_crl = 4;
+
+ message EtcdPeer {
+ string name = 1;
+ string address = 2;
+ }
+ // All other current etcd peers in the cluster.
+ repeated EtcdPeer peers = 5;
+ // The peer that this node should start running.
+ EtcdPeer this = 6;
+
+ // Node configuration. Currently unused (in the future, this will be used to run a node
+ // management service separate from etcd clustering).
+ string node_id = 7;
+ bytes node_cert = 8;
+ bytes node_key = 9;
+}