Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: allow masking workspace parameter inputs#18595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
aslilac wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromlilac/mask-input
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletionscoderd/apidoc/docs.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

3 changes: 3 additions & 0 deletionscoderd/apidoc/swagger.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

1 change: 1 addition & 0 deletionscoderd/database/db2sdk/db2sdk.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -816,6 +816,7 @@ func PreviewParameter(param previewtypes.Parameter) codersdk.PreviewParameter {
Placeholder: param.Styling.Placeholder,
Disabled: param.Styling.Disabled,
Label: param.Styling.Label,
MaskInput: param.Styling.MaskInput,
},
Mutable: param.Mutable,
DefaultValue: PreviewHCLString(param.DefaultValue),
Expand Down
1 change: 1 addition & 0 deletionscodersdk/parameters.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,7 @@ type PreviewParameterStyling struct {
Placeholder *string `json:"placeholder,omitempty"`
Disabled *bool `json:"disabled,omitempty"`
Label *string `json:"label,omitempty"`
MaskInput *bool `json:"mask_input,omitempty"`
}

type PreviewParameterOption struct {
Expand Down
195 changes: 195 additions & 0 deletionsdocs/admin/templates/extending-templates/mask-input-example.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
# Mask Input Feature

The `mask_input` styling option allows you to hide sensitive parameter values by converting all characters to asterisks (*). This feature is designed for template parameters that contain sensitive information like passwords, API keys, or other secrets.

> **Note**: This feature is purely cosmetic and does not provide any security. The actual parameter values are still transmitted and stored normally. This is only meant to hide the characters visually in the UI.

## Usage

The `mask_input` option can be applied to parameters with `form_type` of `input` or `textarea`. Add it to the `styling` block of your parameter definition:

```hcl
variable "api_key" {
description = "API key for external service"
type = string
sensitive = true

validation {
condition = length(var.api_key) > 0
error_message = "API key cannot be empty."
}
}

resource "coder_parameter" "api_key" {
name = "api_key"
display_name = "API Key"
description = "Enter your API key for the external service"
type = "string"
form_type = "input"
mutable = true

styling = {
mask_input = true
placeholder = "Enter your API key"
}
}
```

## Examples

### Masked Input Field

```hcl
resource "coder_parameter" "database_password" {
name = "database_password"
display_name = "Database Password"
description = "Password for database connection"
type = "string"
form_type = "input"
mutable = true

styling = {
mask_input = true
}
}
```

### Masked Textarea Field

```hcl
resource "coder_parameter" "private_key" {
name = "private_key"
display_name = "Private Key"
description = "Private key for SSH access"
type = "string"
form_type = "textarea"
mutable = true

styling = {
mask_input = true
placeholder = "Paste your private key here"
}
}
```

### Complete Example with Multiple Sensitive Parameters

```hcl
terraform {
required_providers {
coder = {
source = "coder/coder"
}
}
}

variable "username" {
description = "Username for the service"
type = string
}

variable "password" {
description = "Password for the service"
type = string
sensitive = true
}

variable "ssl_certificate" {
description = "SSL certificate content"
type = string
sensitive = true
}

resource "coder_parameter" "username" {
name = "username"
display_name = "Username"
description = "Enter your username"
type = "string"
form_type = "input"
mutable = true
default_value = var.username
}

resource "coder_parameter" "password" {
name = "password"
display_name = "Password"
description = "Enter your password"
type = "string"
form_type = "input"
mutable = true
default_value = var.password

styling = {
mask_input = true
placeholder = "Enter your password"
}
}

resource "coder_parameter" "ssl_certificate" {
name = "ssl_certificate"
display_name = "SSL Certificate"
description = "Paste your SSL certificate"
type = "string"
form_type = "textarea"
mutable = true
default_value = var.ssl_certificate

styling = {
mask_input = true
placeholder = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"
}
}
```

## User Interface Behavior

When `mask_input` is enabled:

1. **Masked Display**: All characters in the input field are displayed as asterisks (*)
2. **Show/Hide Toggle**: A eye icon button appears in the top-right corner of the field
- Click the eye icon to reveal the actual text
- Click again to hide it back to asterisks
3. **Normal Functionality**: The field works normally for typing, copying, and pasting
4. **Form Submission**: The actual unmasked value is submitted with the form

## Limitations and Considerations

- **No Security**: This feature provides no actual security - it's purely visual
- **Number Fields**: Masking is automatically disabled for `number` type parameters
- **Accessibility**: Screen readers will still read the actual values, not the masked version
- **Development**: Use in conjunction with Terraform's `sensitive = true` for variables that contain secrets

## Best Practices

1. **Combine with Sensitive Variables**: Always mark sensitive parameters with `sensitive = true` in your Terraform variables
2. **Use Descriptive Placeholders**: Provide helpful placeholder text to guide users
3. **Validate Input**: Add appropriate validation rules for sensitive parameters
4. **Documentation**: Clearly document what sensitive information is being collected

```hcl
variable "api_token" {
description = "API token for external service (keep this secret!)"
type = string
sensitive = true # This prevents the value from appearing in Terraform logs

validation {
condition = can(regex("^[A-Za-z0-9]{32,}$", var.api_token))
error_message = "API token must be at least 32 alphanumeric characters."
}
}

resource "coder_parameter" "api_token" {
name = "api_token"
display_name = "API Token"
description = "Enter your API token (this will be hidden for security)"
type = "string"
form_type = "input"
mutable = true
default_value = var.api_token

styling = {
mask_input = true
placeholder = "Enter your 32+ character API token"
}
}
```
4 changes: 4 additions & 0 deletionsdocs/reference/api/schemas.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

1 change: 1 addition & 0 deletionsdocs/reference/api/templates.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

2 changes: 2 additions & 0 deletionsgo.mod
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,6 +75,8 @@ replace github.com/spf13/afero => github.com/aslilac/afero v0.0.0-20250403163713
// TODO: replace once we cut release.
replace github.com/coder/terraform-provider-coder/v2 => github.com/coder/terraform-provider-coder/v2 v2.7.1-0.20250623193313-e890833351e2

replace github.com/coder/preview => github.com/coder/preview v1.0.2-0.20250625231609-10623f47565b

require (
cdr.dev/slog v1.6.2-0.20241112041820-0ec81e6e67bb
cloud.google.com/go/compute/metadata v0.7.0
Expand Down
4 changes: 2 additions & 2 deletionsgo.sum
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -916,8 +916,8 @@ github.com/coder/pq v1.10.5-0.20240813183442-0c420cb5a048 h1:3jzYUlGH7ZELIH4XggX
github.com/coder/pq v1.10.5-0.20240813183442-0c420cb5a048/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 h1:3A0ES21Ke+FxEM8CXx9n47SZOKOpgSE1bbJzlE4qPVs=
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0/go.mod h1:5UuS2Ts+nTToAMeOjNlnHFkPahrtDkmpydBen/3wgZc=
github.com/coder/preview v1.0.1 h1:f6q+RjNelwnkyXfGbmVlb4dcUOQ0z4mPsb2kuQpFHuU=
github.com/coder/preview v1.0.1/go.mod h1:efDWGlO/PZPrvdt5QiDhMtTUTkPxejXo9c0wmYYLLjM=
github.com/coder/preview v1.0.2-0.20250625231609-10623f47565b h1:nka6oEgL/+GR78IcdwgG6CNDEpgLD1JFGts8h7yLD5w=
github.com/coder/preview v1.0.2-0.20250625231609-10623f47565b/go.mod h1:efDWGlO/PZPrvdt5QiDhMtTUTkPxejXo9c0wmYYLLjM=
github.com/coder/quartz v0.2.1 h1:QgQ2Vc1+mvzewg2uD/nj8MJ9p9gE+QhGJm+Z+NGnrSE=
github.com/coder/quartz v0.2.1/go.mod h1:vsiCc+AHViMKH2CQpGIpFgdHIEQsxwm8yCscqKmzbRA=
github.com/coder/retry v1.5.1 h1:iWu8YnD8YqHs3XwqrqsjoBTAVqT9ml6z9ViJ2wlMiqc=
Expand Down
1 change: 1 addition & 0 deletionssite/src/api/typesGenerated.ts
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -230,3 +230,42 @@ export const AllBadges: Story = {
isPreset: true,
},
};

export const MaskedInput: Story = {
args: {
parameter: {
...MockPreviewParameter,
form_type: "input",
styling: {
...MockPreviewParameter.styling,
mask_input: true,
},
},
},
};

export const MaskedTextArea: Story = {
args: {
parameter: {
...MockPreviewParameter,
form_type: "textarea",
styling: {
...MockPreviewParameter.styling,
mask_input: true,
},
},
},
};

export const MaskedInputWithPlaceholder: Story = {
args: {
parameter: {
...MockPreviewParameter,
form_type: "input",
styling: {
placeholder: "Enter your secret value",
mask_input: true,
},
},
},
};
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp