Extension SDK
alien-extension-sdk is the Rust crate you write an extension with. It has the hooks that change what Alien generates and sends, and the controller side that runs a custom resource.
use acme_types::DnsZone;
use alien_extension_sdk::prelude::*;
mod dns_zone;
mod postgres_iam_auth;
fn register(ext: &mut Extension) {
// A flag on the Postgres database Alien creates.
ext.cloudformation_modifier(postgres_iam_auth::CloudFormation);
ext.terraform_modifier(postgres_iam_auth::Terraform);
ext.aws_interceptor(postgres_iam_auth::Rds);
// A resource type Alien doesn't have.
ext.resource::<DnsZone>()
.permission_set(include_str!("../../permissions/dns-zone/provision.jsonc"))
.cloudformation_emitter(Platform::Aws, dns_zone::AwsCfEmitter)
.terraform_emitter(Platform::Gcp, dns_zone::GcpTfEmitter)
.helm_emitter(Platform::Kubernetes, dns_zone::KubernetesEmitter)
.importer(Platform::Aws, dns_zone::AwsImporter)
.link(dns_zone::link);
}
alien_extension_sdk::export!("acme", register);Workspace manifest
An extension is a Cargo workspace. Its Cargo.toml tells alien extensions build which crate is which:
[workspace]
members = ["types", "hooks", "controller"]
[workspace.metadata.alien-extension]
hooks = "hooks"
controller = "controller"
types = "types"
egress = ["https://api.acme.dev"]| Key | Names |
|---|---|
hooks | The crate with register and every hook. It builds to one WebAssembly module for wasm32-wasip1. |
controller | The crate with your controllers. Its library builds to one WebAssembly module for wasm32-wasip1, and its binary runs the local controller under alien dev. Leave it out when no custom resource has a controller. |
types | The crate with your custom resources' config, outputs, and saved fields, shared by the other two. alien extensions build generates the TypeScript builders from it. |
egress | Optional. The origins your controllers may call besides their cloud, each https://host[:port]. Your release pins them, and the setup template shows them to the customer. |
Preludes
| Module | Import it in | What it brings |
|---|---|---|
alien_extension_sdk::prelude | The hooks crate | What hooks use, such as Extension, the modifier and interceptor traits, CfEmitter, TfEmitter, HelmEmitter, ResourceImporter, Link, and Platform |
alien_extension_sdk::controller_prelude | The controller crate's library | What a controller module uses, such as #[controller] and its attributes, Controllers, ResourceControllerContext, CloudRequest, HttpRequest, CloudResponse, CloudTarget, aws_sdk_error, ErrorData, ResourceStatus, and Platform |
alien_extension_sdk::local_controller_prelude | The controller crate's binary, main.rs and the local controller it registers | What the Platform::Local controller uses under alien dev: #[controller] and its attributes, Controllers, Alien's own ResourceControllerContext, and SingleControllerExecutor |
Each prelude brings its own Result, so hooks and controllers return errors the way Alien's own code does. controller_prelude is the same on every target, so the library that builds to the module also builds natively for its tests.
A hook's error reaches Alien with its code and its message cut to 1 KiB. A hook written with the SDK reports every error as final, since the same input gives the same answer. An error with no code of its own, such as a plain string, has the code HOOK_FAILED. An interceptor's message is dropped, since the hook saw the call it changed.
A hooks crate can depend on alien-core, alien-cloudformation, alien-terraform, and alien-helm. A controller builds for wasm32-wasip1 too, so it can use any Rust crate that builds for that target and opens no sockets or files.
Registration
export!(name, register) declares the extension and calls your register function with an &mut Extension. The name prefixes every type the extension adds, as in acme/dns-zone. The names alien and experimental are reserved.
Method on Extension | Registers |
|---|---|
cloudformation_modifier(m) | A CloudFormationModifier |
terraform_modifier(m) | A TerraformModifier |
helm_modifier(m) | A HelmModifier |
aws_interceptor(i) | An AwsInterceptor |
gcp_interceptor(i) | A GcpInterceptor |
azure_interceptor(i) | An AzureInterceptor |
kubernetes_interceptor(i) | A KubernetesInterceptor |
resource::<T>() | A custom resource type T, declared with #[alien_resource]. Returns a builder for the methods below. |
Method on ext.resource::<T>() | Adds |
|---|---|
permission_set(jsonc) | A permission set, one per call |
cloudformation_emitter(platform, e) | The resource's part of the CloudFormation template, a CfEmitter |
terraform_emitter(platform, e) | The resource's part of the Terraform module, a TfEmitter |
helm_emitter(platform, e) | The resource's part of the Helm chart, a HelmEmitter |
importer(platform, i) | A ResourceImporter that turns setup template outputs into the controller's saved fields |
link(f) | A Link function, called with the resource's outputs when a workload links to it |
platform is Platform::Aws, Platform::Gcp, Platform::Azure, or Platform::Kubernetes. Each emitter you register turns on one setup path for stacks that use the type, as Custom resources explains.
Template modifiers
A modifier gets the template Alien generated for initial setup and returns a changed one. It runs in the package builder and in alien render. Both apply the same modifiers, so both show the same resources.
- Modifiers run in the order
registeradds them. Across extensions, they run in the order.extensions([...])lists them inalien.ts. - A modifier can add resources. A CloudFormation modifier can add, change, or remove properties. A Terraform modifier adds and changes attributes; the SDK has no call that removes one Alien emitted.
- A modifier can't remove, hide, or retype a resource Alien emits. The build fails and names the extension.
CloudFormationModifier
impl CloudFormationModifier for CloudFormation {
fn modify(&self, mut template: CfTemplate) -> Result<CfTemplate> {
for cluster in template.resources_of_type_mut("AWS::RDS::DBCluster") {
cluster.set_property("EnableIAMDatabaseAuthentication", true);
}
Ok(template)
}
}CfTemplate | |
|---|---|
resources_of_type_mut(type) | Every resource of a CloudFormation type, such as AWS::RDS::DBCluster |
set_property(name, value) | Sets a property on one of those resources |
TerraformModifier
impl TerraformModifier for Terraform {
fn modify(&self, mut module: TfModule) -> Result<TfModule> {
for cluster in module.resources_of_type_mut("aws_rds_cluster") {
cluster.set_attribute("iam_database_authentication_enabled", true);
}
Ok(module)
}
}TfModule | |
|---|---|
resources_of_type_mut(type) | Every resource block of a Terraform type, such as aws_rds_cluster |
set_attribute(name, value) | Sets an attribute on one of those blocks, or adds it |
block_mut(name) | A nested block Alien emitted, such as settings. Fails if the block isn't there |
add_block(name) | Adds a nested block and returns it |
add_resource(type, name) | Adds an empty resource block to <extension>.tf, the one file a modifier writes besides Alien's, and returns it |
add_data_source(type, name) | Adds an empty data block to <extension>.tf, to read a value Alien's blocks don't carry, such as the Azure tenant from azurerm_client_config |
TfModule edits Alien's own .tf files in place. Alien writes back only the files your modifier changed, and keeps their formatting, so they still pass terraform fmt -check.
HelmModifier
A HelmModifier adds files to the chart and can't change Alien's. Register it with ext.helm_modifier.
Its one method, templates(&self, chart: &HelmChart) -> Result<BTreeMap<String, String>>, gets the chart's files and returns new files, keyed by file name. They go in the extension's own subchart, charts/<extension>/templates/. Template modifiers lists the rules a file follows.
Interceptors
An interceptor runs inside a call Alien's controllers make to the cloud or to Kubernetes, before Alien signs it. It can change the request's parameters, query and body, and the response. On Kubernetes it may only add labels to the object.
pub struct Rds;
impl AwsInterceptor for Rds {
fn matches(&self, call: &AwsCall) -> bool {
call.service() == "rds"
&& matches!(call.operation(), "CreateDBCluster" | "ModifyDBCluster")
}
fn modify_request(&self, request: &mut AwsRequest) -> Result<()> {
request.set("EnableIAMDatabaseAuthentication", true);
Ok(())
}
}| Trait | matches gets | modify_request gets | modify_response gets |
|---|---|---|---|
AwsInterceptor | AwsCall: service() and operation(), such as rds and CreateDBCluster | &mut AwsRequest | &mut AwsResponse |
GcpInterceptor | GcpCall: Alien's service key and the route, such as cloudsql and matches_route("POST", "projects/*/instances") | &mut GcpRequest | &mut GcpResponse |
AzureInterceptor | AzureCall: the resource provider, the resource type, and the HTTP method, such as Microsoft.DBforPostgreSQL, flexibleServers, and PUT. tenant_id() gives the call's Azure tenant | &mut AzureRequest | &mut AzureResponse |
KubernetesInterceptor | KubernetesCall: the object's kind and the verb, such as Pod and create | &mut KubernetesObject, the object the Operator sends | &mut KubernetesObject, the object returned |
matches and modify_request are required. modify_response is optional and leaves the response unchanged by default. It also sees error responses.
AWS requests
An AwsRequest reads and writes the call in the wire format the AWS API uses:
| AWS API | Services | Request view | Response view |
|---|---|---|---|
| Query | RDS, EC2, SQS, and others | param(key), set(key, value), remove(key) over the flat form keys, such as Tags.Tag.1.Key, and push_member(prefix, ...) to add an item to an indexed list. The Action key names the operation. | AwsResponse::xml(), the XML as text, with get(path) and set(path, value) |
| JSON | DynamoDB, KMS, Secrets Manager, SSM, and others | body_mut(), the body as JSON, which fails on a query API. set sets a top-level field, and body_mut() reaches nested ones. The X-Amz-Target header names the operation. | The body as JSON |
| REST with JSON | Lambda, API Gateway, EKS, and others | method and path to read, query, and the body as JSON | The body as JSON |
| REST with XML | S3 | method and path to read, query, headers, and the XML as text | The XML as text |
request.set("EnableIAMDatabaseAuthentication", true) works on a query API, where it sets the form value true, and on a JSON API, where it sets a top-level field. In a test, build a request with AwsRequest::new(service, operation, body) and read it back with param(key), which returns the form value as text, such as Some("true").
Google Cloud, Azure, and Kubernetes requests
| View | Request | Response |
|---|---|---|
GcpRequest | method and path to read, query, and body_mut(), the body as JSON | The body as JSON |
AzureRequest | method, path, api_version, call() for the matched AzureCall, and body_mut(), the body as JSON | The body as JSON, and the headers |
KubernetesObject | body_mut(), the object as JSON, with its kind, verb, and namespace. Only labels may be added to metadata.labels, each a string, with no prefix and not managed-by | The object as JSON, which may not change |
What an interceptor can't change
- The destination. Alien refuses a change to the scheme, host, or port, or to the cloud or service.
- The method, the path, and the operation (the
Actionkey or theX-Amz-Targetheader). - The identities the call names: a service account, a role, a managed identity, or a pod's service account.
- What kind of call it is: a call can't become a policy or IAM call. Alien's own IAM, role-assignment and policy calls are never offered.
- The headers that carry or protect a credential, and the other changes Interceptors lists. An interceptor never sees credentials.
- Binary and streamed bodies, such as S3
PutObject, LambdaInvoke, and Cloud Storage uploads, are never offered. When your interceptor would match one, the call fails with an error that names your extension.
After you change a body, Alien recomputes x-amz-content-sha256, Content-MD5, and Content-Length. A failed modify_response is final, since the cloud already acted on the call. A failed matches or modify_request stops the step, which is tried again only when the hook reached its time limit or its error says another try may pass. Interceptors lists which calls Alien intercepts.
Custom resources
#[alien_resource]
#[alien_resource] declares a custom resource type on a struct in your types crate:
#[alien_resource(type = "acme/dns-zone", outputs = DnsZoneOutputs, lifecycles = [Frozen, Live], holds_data = false)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, utoipa::ToSchema, bon::Builder)]
#[serde(rename_all = "camelCase")]
#[builder(start_fn = new)]
pub struct DnsZone {
#[builder(start_fn)]
pub id: String,
/// The zone's domain, for example "internal.acme.dev".
pub domain: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct DnsZoneOutputs {
pub zone_id: String,
}| Argument | Value |
|---|---|
type | The type name, <extension>/<type>. The extension part matches the name in export!. |
outputs | The struct a linked workload and your link function see |
lifecycles | [Frozen], [Live], or [Frozen, Live]. A type with no controller can only be Frozen. |
holds_data | Whether the resource holds your customer's data |
It writes the RESOURCE_TYPE constant and the definitions Alien's own resources write by hand.
Emitters
Emitters are Alien's own traits. Your types implement them the way Alien's resources do, with the same helpers, such as resource_config and downcast.
| Trait | Method | Returns |
|---|---|---|
CfEmitter | emit_resources(ctx) | The CloudFormation resources that back the resource, a Vec<CfResource> |
emit_import_ref(ctx) | The CfExpression that resolves to the importer's input after the template is applied | |
TfEmitter | emit(ctx) | The Terraform blocks that back the resource, a TfFragment |
emit_import_ref(ctx) | The Expression that resolves to the importer's input after the module is applied | |
HelmEmitter | emit(ctx) | A HelmFragment: an entry in values.yaml, and extra files for templates/ |
Each method gets an EmitContext, with the resource's id in ctx.resource_id. In a pull deployment set up with Helm, nothing is created in the cloud, so a frozen resource's Helm entry points at one your customer already has.
Importers
After your customer applies the setup template, the importer turns the template's outputs into the fields your controller saves.
impl ResourceImporter for AwsImporter {
type ImportData = AwsDnsZoneImport;
fn import(&self, data: AwsDnsZoneImport, ctx: &ImportContext<'_>) -> Result<StackResourceState> {
let outputs = DnsZoneOutputs { zone_id: data.zone_id.clone() };
ctx.ready(AwsDnsZoneFields { zone_id: Some(data.zone_id) }, outputs)
}
}ImportData is what emit_import_ref resolves to. ctx.ready(fields, outputs) builds the StackResourceState from the controller's fields and the resource's outputs. Alien adds the type tag and the state version.
Your controller's first step loads the fields, so keep the fields type in types/ for both crates.
Every importer needs fixtures under tests/import/<resource-type>/<platform>/. alien extensions test and alien release run each one through the importer and load the result into your controller or, for a type with no controller, check its outputs against the outputs type. They fail when the two disagree.
alien extensions test, and alien release from the extension's workspace, refuse an importer with no fixtures. See Testing.
Links
A link says what a workload gets when it links to the resource:
pub fn link(outputs: &DnsZoneOutputs) -> Link {
Link::new()
.env("ACME_ZONE_ID", &outputs.zone_id)
.permission_set("acme/dns-zone/records-write")
}Link | |
|---|---|
Link::new() | An empty link |
.env(name, value) | An environment variable the workload gets |
.permission_set(id) | A permission set the workload gets on the resource |
Permission sets
Each permission_set call takes one set, in the JSONC format of custom permission sets. Its id is <extension>/<type>/<name>, such as acme/dns-zone/provision. Initial setup creates an identity for the extension from its provision, management and heartbeat sets, and Alien signs its controller's calls as that identity.
Declare any grant your controller needs in those three sets, with no change to Alien. The customer sees every grant in the setup template. A stack is refused, naming the set and the grant, only when one of them:
- reads stored customer data, such as an object, an item, a secret, a message or a log, wildcards included;
- changes IAM or who has access;
- acts as another identity;
- names a predefined Google Cloud or Azure role.
Security lists what each covers, and the ordinary updates allowed although they can set a password or change an app's image. Give a workload that needs the data a set the type links instead.
Services and network
A type that needs a cloud service turned on, or the stack's network, says so on its registration:
| Method | Effect |
|---|---|
.requires_services(Platform::Gcp, ["dns.googleapis.com"]) | Alien enables these GCP APIs, or Azure resource providers such as Microsoft.Network, with the ones its own types need |
.requires_network() | Alien creates the stack's network on AWS, Google Cloud and Azure, as it does for its own types that need one |
.private_network_endpoints() | The type serves at private addresses inside the stack's network, so a sandbox image may declare a direct connection to it. Implies requires_network() |
Controllers
A controller is the code that creates, updates, and deletes a custom resource in the cloud. It uses the same model as Alien's own controllers, a state machine of handlers that runs one step at a time.
use acme_types::{AwsDnsZoneFields, DnsZone};
use alien_extension_sdk::controller_prelude::*;
#[controller]
pub struct AwsDnsZoneController {
#[serde(flatten)]
fields: AwsDnsZoneFields, // the same fields the importer fills
}
#[controller]
impl AwsDnsZoneController {
#[flow_entry(Create)]
#[handler(state = CreateStart, on_failure = CreateFailed, status = ResourceStatus::Provisioning)]
async fn create_start(&mut self, ctx: &ResourceControllerContext<'_>) -> Result<HandlerAction> {
let zone = ctx.desired_resource_config::<DnsZone>()?;
let route53 = aws_sdk_route53::Client::new(&ctx.aws_sdk_config().await?);
// Create the zone with a caller reference unique to this resource, save its id ...
Ok(HandlerAction::Continue { state: Ready, suggested_delay: None })
}
// Ready, the Update and Delete flows, and build_outputs ...
terminal_state!(state = CreateFailed, status = ResourceStatus::ProvisionFailed);
terminal_state!(state = Deleted, status = ResourceStatus::Deleted);
}#[controller]
| Item | Use |
|---|---|
#[controller] on the struct | Adds the state the controller saves between steps. Your fields are saved with it. |
#[controller] on the impl | Builds the state machine from the handlers below |
#[flow_entry(Create)], #[flow_entry(Update)], #[flow_entry(Delete)] | Marks the handler a flow starts at. Update can take from = [...], the states it may start from. Delete can't. A controller needs a Create entry, and without an Update flow a config change fails with "No update flow defined". |
#[handler(state, on_failure, status, progress)] | A handler for one state. on_failure is the state a failed step moves to, status is the resource's status while in this state, and the optional progress is a line the dashboard shows next to the resource. |
terminal_state!(state, status) | A state with no handler, such as CreateFailed or Deleted, and its status |
HandlerAction::Continue { state, suggested_delay } | Moves to state. A Ready handler returns a delay, such as Some(Duration::from_secs(60)), and never None. |
HandlerAction::Stay { max_times, suggested_delay } | Runs the same handler again after the delay, to poll. Past max_times, the step fails. |
fn build_outputs(&self) -> Option<ResourceOutputs> | The outputs a linked workload and your link function see |
ResourceControllerContext
| Member | Gives |
|---|---|
desired_resource_config::<T>() | The resource's config from the stack, as &T |
previous_resource_config::<T>() | The config before the change. Only an update has one. |
desired_config | The same config as Alien's Resource, for its id() and resource_type() |
platform | The Platform the resource runs on |
resource_prefix | The deployment's prefix for cloud resource names |
aws_sdk_config().await | An AWS SDK config for any aws-sdk-* client added with default-features = false. Its requests go through Alien, which signs them. The client sends each call once. |
cloud() | The step's cloud: send for a request to it, http for a request to a declared origin, and target() for where its calls go |
dependency_outputs::<T>(id) | The outputs of a resource this one depends on, read as your type T. It fails with DEPENDENCY_NOT_READY while the dependency has none, and Alien steps the resource again when it has. |
time_left() | A Duration: how long the step has before its deadline, and zero once it has passed |
emit_heartbeat(heartbeat) | Reports the resource's health, a ResourceHeartbeat. Alien refuses a reply whose report names another resource, and a failed step reports nothing. |
Use dependency_outputs. A controller never sees another resource's saved state. The prelude brings the types a heartbeat is built from, such as ResourceHeartbeat, CustomHeartbeat, and ObservedHealth.
Cloud requests
A controller holds no credentials and opens no sockets. It builds a request, and Alien signs and sends it:
| Item | Use |
|---|---|
CloudRequest::aws(service, method, path) | A request to an AWS service, named by its endpoint prefix, such as route53 |
CloudRequest::gcp(service, method, path) | A request to https://<service>.googleapis.com, such as dns |
CloudRequest::azure(method, path) | A request to Azure Resource Manager |
.region(name), .query(key, value), .header(name, value) | Set the rest of a CloudRequest. region is for AWS, and defaults to the step's. |
.body(text), .body_bytes(&bytes), .json(&value)? | Set the body. json serializes value, sets content-type: application/json, and returns a Result. |
HttpRequest::new(method, url) | A request to an origin egress declares. url is an absolute https URL. It takes .header, .body, .body_bytes, and .json as a CloudRequest does. |
ctx.cloud().send(&request) | Sends a CloudRequest once and returns a CloudResponse, whatever its status |
ctx.cloud().http(&request) | Sends an HttpRequest once, with none of the deployment's credentials, and returns a CloudResponse |
ctx.cloud().target() | Where the step's calls go, an Option<&CloudTarget>: Aws { account_id, region }, Gcp { project_id, region }, or Azure { subscription_id, tenant_id }. None when the step has no cloud credentials. |
A CloudResponse has the fields status, headers, and body, and these methods:
| Method | Gives |
|---|---|
.is_success() | Whether the status is a 2xx |
.ok(what) | The response on a 2xx. Otherwise .error(what) |
.error(what) | The error Alien's own clients return for the status, with a message that starts with what: REMOTE_RESOURCE_NOT_FOUND for a 404, REMOTE_ACCESS_DENIED for a 401 or 403, REMOTE_RESOURCE_CONFLICT for a 409, RATE_LIMIT_EXCEEDED for a 429, and REMOTE_SERVICE_UNAVAILABLE for a 5xx |
.json::<T>() | The body read as JSON |
.bytes() | The body's bytes, for a body that isn't text |
AWS has the typed aws-sdk-* clients through aws_sdk_config(). Google Cloud and Azure have these request builders, not typed clients. Controllers lists where Alien sends each request and what it refuses.
aws_sdk_error
aws_sdk_error(error) turns the error of an AWS SDK call into Alien's, with the code and retry flag Alien's own AWS clients give the same answer:
let zones = route53
.list_hosted_zones_by_name()
.dns_name(domain)
.send()
.await
.map_err(aws_sdk_error)
.context(ErrorData::CloudPlatformError {
message: "Failed to list the Route53 hosted zones for the domain".to_string(),
resource_id: Some(resource_id.to_string()),
})?;| The call | Code | Retried |
|---|---|---|
| Was throttled | RATE_LIMIT_EXCEEDED | Yes |
| Got a 404, 401 or 403, 409, or 5xx | The code CloudResponse::error gives that status | Yes |
| Got no answer | HTTP_REQUEST_FAILED | Yes |
| Was refused by Alien | EXTENSION_CALL_REFUSED | No |
| Was never sent by the SDK | EXTENSION_REQUEST_INVALID | No |
into_alien_error() on an SDK error gives one that is never retried, also for a throttled call.
export_controllers!
The controller crate's library registers one controller per type and cloud, and export_controllers! exports them from the module:
use acme_types::DnsZone;
use alien_extension_sdk::controller_prelude::*;
pub mod aws;
pub mod azure;
pub mod gcp;
/// Registers the zone's controller for each cloud.
pub fn register(controllers: &mut Controllers) {
controllers.register(
DnsZone::RESOURCE_TYPE,
Platform::Aws,
aws::AwsDnsZoneController::default(),
);
controllers.register(
DnsZone::RESOURCE_TYPE,
Platform::Gcp,
gcp::GcpDnsZoneController::default(),
);
controllers.register(
DnsZone::RESOURCE_TYPE,
Platform::Azure,
azure::AzureDnsZoneController::default(),
);
}
alien_extension_sdk::export_controllers!(register);export_controllers! speaks the step protocol for you. Built for wasm32-wasip1 it writes the module's exports, and built natively it writes nothing. Alien runs the module in a sandbox in the manager, the Operator, and the setup CLI.
alien extensions build builds the library to controller.wasm and reads each type's platforms from the module. It refuses a library that registers Platform::Local, which belongs to the crate's binary.
- Safe to repeat. A step can run again when it ends without a reply, so every call a handler sends must be safe to repeat. Pass a key the cloud checks, as
caller_referencedoes for a Route53 zone. - 60 seconds a step. A request still open at the deadline is cut, and one sent after it is refused. Either way the step fails with
EXTENSION_STEP_DEADLINEand runs again from the state Alien last saved, whatever the handler returned. For longer work, start it in one handler and poll withStay. - One send per call. Alien sends each request once, and the AWS SDK's own retries are off. Return the error, and Alien runs the step again when the error is retryable.
run_controllers
alien dev runs no module. The controller crate's binary registers the local controller with run_controllers, and alien dev starts it as a process:
use acme_types::DnsZone;
use alien_extension_sdk::local_controller_prelude::*;
mod local;
fn main() -> std::process::ExitCode {
alien_extension_sdk::run_controllers(|controllers| {
// Records the zone and returns a placeholder id, with no cloud call.
controllers.register(
DnsZone::RESOURCE_TYPE,
Platform::Local,
local::LocalDnsZoneController::default(),
);
})
}run_controllers reads steps on stdin and writes replies on stdout. Run with --controllers, it prints each type's platforms for alien extensions build and exits. It takes no other argument.
The binary runs only Platform::Local controllers. alien extensions build refuses one that registers another platform.
Controller tests
controller_module::testing::answer(register, &request, host) steps a module controller in a native test. request is a step as Alien sends it, and host is a closure that answers each call the handler makes. Testing shows it.
SingleControllerExecutor, from local_controller_prelude, steps a local controller the way Alien's own controller tests do.
Hook limits
Hooks run in a sandbox inside whichever Alien process needs them. Each call has these limits:
| Limit | Value |
|---|---|
| Time for a modifier or an emitter | 2 seconds |
| Time for an interceptor or an importer | 100 ms |
| Memory | 64 MiB |
| Output | 16 MiB |
| stderr kept in the error | 1 KiB |
A hook over a limit fails, and Alien keeps running. A panic fails the hook too, and export! puts the panic message in the error.
A hook gives the same output for the same input on every run:
- It has no files, network, environment variables, or arguments.
- Every clock reads 0.
- Its random source is seeded with a constant, so iterating a
HashMapgives the same order every time.
Controller limits
A controller module runs in the same sandbox as a hook, with no files, sockets, or environment variables. Unlike a hook, it reads the real clock and real random numbers. Each step has these limits:
| Limit | Value |
|---|---|
| Time for a step | 60 seconds. Alien stops a module that hasn't replied 2 seconds later. |
| Computation in a step | About 4 billion WebAssembly instructions. Time spent in a cloud call doesn't count. |
| Memory | 64 MiB |
| Reply | 16 MiB |
| Module size | 64 MiB |
| Requests in a step | 50 |
| Request body | 6 MiB, with no streaming upload |
| Response body | 8 MiB |
| Steps of one deployment running at once | 2 |
| Steps of one project running at once in one Alien process | 16 |
| Steps running at once in one Alien process | 64 |
A request over a limit is refused. A step over its time, computation, or memory is stopped and retried, and Alien keeps running. A step past the limit on steps running at once waits for one to end.
Next
- Step protocol: what
export_controllers!speaks, for a controller in another language - Custom resources: emitters, importers, and setup paths
- Controllers: where controllers run and whose credentials sign their calls
- Testing: test hooks and controllers before a release