Skip to content

About

SDK for building Marmot plugins.

Resources

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

57 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

plugin-sdk

SDK for building external Marmot plugins.

Marmot plugins are standalone binaries that the Marmot host launches on demand via go-plugin and talks to over gRPC. This SDK provides everything both sides need: the wire protocol, the plugin-facing types and helpers, and the host-side client.

Writing a plugin

A plugin implements the Source interface and hands it to Serve in its main function:

package main

import (
	"context"

	pluginsdk "github.com/marmotdata/plugin-sdk"
)

type Config struct {
	pluginsdk.BaseConfig `json:",inline"`

	ProjectID string `json:"project_id" description:"Project to discover" validate:"required"`
}

type Source struct{}

func (s *Source) Validate(raw pluginsdk.RawConfig) (pluginsdk.RawConfig, error) {
	config, err := pluginsdk.UnmarshalConfig[Config](raw)
	if err != nil {
		return nil, err
	}
	pluginsdk.ApplyDefaults(config, raw)
	if err := pluginsdk.ValidateStruct(config); err != nil {
		return nil, err
	}
	return raw, nil
}

func (s *Source) Discover(ctx context.Context, raw pluginsdk.RawConfig) (*pluginsdk.DiscoveryResult, error) {
	// discover assets, lineage, and documentation here
	return &pluginsdk.DiscoveryResult{}, nil
}

func main() {
	pluginsdk.Serve(&pluginsdk.ServeConfig{
		Meta: pluginsdk.Meta{
			ID:          "example",
			Name:        "Example",
			Description: "Discovers things from Example",
			Icon:        "example",
			Category:    "storage",
			ConfigSpec:  pluginsdk.GenerateConfigSpec(Config{}),
		},
		Source: &Source{},
	})
}

Build the binary with a marmot-plugin- name prefix and drop it in ~/.marmot/plugins (or the directory set by MARMOT_PLUGINS_DIR). Marmot discovers it at startup, fetches its metadata, and registers it; a local binary shadows a downloaded core plugin with the same ID. Plugin processes are short-lived: the host spawns the binary per call and kills it, and the SDK runs Validate before Discover in each process, so state your Validate sets on the Source is there when Discover runs.

A Source can optionally implement DataFetcher to power sample-row previews on asset pages; Serve detects it automatically. Test your built binary over the real wire protocol with the plugintest package.

See Creating a Marmot Plugin for a step-by-step guide.

Config specs

GenerateConfigSpec reflects over your config struct's tags to produce the settings form Marmot renders in its UI:

  • json: field name
  • label: display label in sentence case, such as label:"Pull requests" (defaults to the field name in sentence case, keeping initialisms such as URL and ID)
  • description: shown as a tooltip beside the field, so keep it to one or two plain sentences and never name config keys in it
  • validate: required marks the field required; oneof=a b c renders a dropdown
  • sensitive:"true": renders as a password field and masks the value
  • hidden:"true": kept in the spec, so Marmot still encrypts and masks it, but not shown in the form
  • file:"true": the value is a path the plugin reads on its own machine, such as a token or certificate file; a host that runs plugins for other people refuses paths it has not allowed
  • default: default value
  • group: the form section the field belongs to (see below)
  • show_when: shows the field only while another field meets a condition:
Tag Shown while
show_when:"branches:active" branches equals active
show_when:"branches:equals:active" the same, spelt out
show_when:"branches:not_equals:all" branches is anything but all
show_when:"connection:set" connection has a non-empty value
show_when:"connection:unset" connection is empty or absent

A second part naming an operator is always the operator, so a field shown when another equals the literal set is show_when:"mode:equals:set". A tag that does not parse panics when the spec is generated. The field named is a sibling, or a top-level field when no sibling has that name; call ValidateConfigSpec(spec) in a test to check every show_when names a field that exists. In the JSON spec, equals is sent without an operator, so it reads the same to hosts that predate operators.

Fields without a group are shown first. Other groups follow as expanded sections in the order they first appear, except Advanced, which is collapsed at the bottom; put anything rarely needed there. A group whose fields are all booleans renders as a checklist. DeriveSpec with Override(name, Description(...), Group(...)) adjusts a field that comes from an embedded struct, such as zone.

The default tag pre-fills the UI form; call ApplyDefaults(config, raw) in Validate so defaults also apply to configs written by hand.

BaseConfig (embed it inline) adds the standard tags, external_links, filter and zone fields every plugin supports. Filtering is applied by the host after discovery; plugins only carry the config.

Sign-in methods

A plugin lists its ways to sign in in Meta.SignIn, so Marmot offers them as a choice and asks only for the chosen one's settings. Each SignInMethod names its settings in Fields and Required by path (url, or credentials.role_arn for one inside an object), with a Label and a one-line Description of what the person does.

A method with Identity: SignInIdentityMarmot signs in with Marmot's workload identity: a short-lived token Marmot mints for the pipeline on every call, with no secret to store. Embed Federation in the config, and declare how the system takes the token in Federation:

Kind The system Audience
cloud-sts with Cloud aws, gcp or azure Swaps the token at its token service. Use AWSIdentitySignIn(), GCPIdentitySignIn() or AzureIdentitySignIn() for the SDK's credentials object, or their ...At(path) forms for settings kept elsewhere The one the cloud expects
bearer Takes the token on each request The origin of the URL in the AudienceFrom setting
client-assertion, token-exchange Swaps it at an OAuth token endpoint The origin of the URL in the AudienceFrom setting

The host derives the audience with DeriveAudience and never mints for the one a config asks for, so a source pointed at another server gets no token yours would accept; call it in Validate too and write the result back with SetAudience. Read the current token with IdentityToken(ctx), or hand IdentityTokenFile(ctx) to a client that re-reads a file. Trust lists the steps that make the system trust Marmot, with {{issuer}}, {{issuer_host}}, {{jwks_uri}}, {{subject}}, {{audience}} and {{config.<setting>}} filled in by the host. Call ValidateSignIn(meta.SignIn, meta.ConfigSpec) in a test.

Identity: SignInIdentityKubernetes is the service account of the cluster the host runs in, which a plugin finds on its own.

A system that takes the token itself gets it through one of these, each sending it only to the origin of the config's audience, so nothing redirected or built from another setting carries it elsewhere:

Helper Kind What it does
IdentityBearerTransport(ctx, audience, base) bearer An http.RoundTripper that adds Authorization: Bearer <token>, read afresh per request
IdentityHeaderTransport(ctx, audience, header, prefix, base) bearer The same, in a header of the system's own
IdentityClientAssertion(ctx, ClientAssertionConfig) client-assertion An oauth2.TokenSource using the token as the client assertion (RFC 7523)
IdentityTokenExchange(ctx, TokenExchangeConfig) token-exchange An oauth2.TokenSource swapping the token for the system's own (RFC 8693)

A database a cloud manages takes a short-lived password made from the cloud's credentials. Keep AWSDatabaseIdentity, GCPDatabaseIdentity and AzureDatabaseIdentity in aws, gcp and azure settings, declare AWSDatabaseSignIn(), GCPDatabaseSignIn() and AzureDatabaseSignIn() (each takes the engine's own trust steps, such as creating the database user), call FederateDatabase in Validate, and ask DatabasePassword for the password each time a connection opens: an RDS IAM authentication token, a Cloud SQL sign-in token of a service account, or an Entra ID token for AzureOSSRDBMSScope or AzureSQLScope.

To test a plugin that signs in with Marmot's identity, plugintest.NewIssuer(t) starts a fake issuer that publishes a discovery document and key set and mints tokens shaped as Marmot's. issuer.Context(t, ctx, subject, audience) gives a call context carrying a token, issuer.Minter(subject) is the minter to put on a context for a built binary, and issuer.Verify(token, audience) checks a token as a fake system would.

Protocol

The handshake pins ProtocolVersion (currently 1). Bump it on breaking changes to the wire protocol; hosts refuse plugins built against a different version. Adding an RPC is not breaking: old plugins answer it with Unimplemented. Regenerate the gRPC code after editing proto/plugin.proto:

protoc --go_out=. --go_opt=paths=source_relative \
  --go-grpc_out=. --go-grpc_opt=paths=source_relative \
  proto/plugin.proto

About

SDK for building Marmot plugins.

Resources

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages