@akeyless-community/railway-sync 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +145 -0
- package/action/action.yml +78 -0
- package/bin/akeyless-railway-sync.js +2 -0
- package/dist/akeyless.d.ts +12 -0
- package/dist/akeyless.js +69 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +82 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.js +71 -0
- package/dist/config.test.d.ts +1 -0
- package/dist/config.test.js +21 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +114 -0
- package/dist/railway.d.ts +18 -0
- package/dist/railway.js +70 -0
- package/dist/types.d.ts +36 -0
- package/dist/types.js +1 -0
- package/examples/github-workflow/sync-secrets.yml +23 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Akeyless Community
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Akeyless + Railway Push Sync
|
|
2
|
+
|
|
3
|
+
Sync static secrets from [Akeyless](https://www.akeyless.io) to [Railway](https://railway.com) service or shared environment variables — the same push pattern used by Doppler and Infisical.
|
|
4
|
+
|
|
5
|
+
**Repository:** [github.com/akeyless-community/railway-akeyless-sync](https://github.com/akeyless-community/railway-akeyless-sync)
|
|
6
|
+
|
|
7
|
+
Pair with [@akeyless-community/railway-runtime](https://github.com/akeyless-community/railway-runtime) if you prefer runtime pull instead of push sync.
|
|
8
|
+
|
|
9
|
+
## Why this integration
|
|
10
|
+
|
|
11
|
+
Railway injects configuration as environment variables at deploy time. Akeyless stays the source of truth; this tool pushes secrets to Railway via the public GraphQL API (`variableCollectionUpsert`).
|
|
12
|
+
|
|
13
|
+
**Use cases:**
|
|
14
|
+
- Sync API keys and database credentials to a Railway service
|
|
15
|
+
- Rotate secrets in Akeyless and propagate via GitHub Actions
|
|
16
|
+
- Keep bootstrap-only vars on Railway and push application secrets from Akeyless
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
### 1. Prerequisites
|
|
21
|
+
|
|
22
|
+
- [Akeyless](https://console.akeyless.io) static secrets under a folder, e.g. `/railway/my-project/production`
|
|
23
|
+
- A Railway **account or workspace** API token ([railway.com/account/tokens](https://railway.com/account/tokens))
|
|
24
|
+
- Railway project, environment, and optional service IDs (Cmd/Ctrl+K in dashboard → Copy … ID)
|
|
25
|
+
|
|
26
|
+
> **Note:** Project-scoped tokens do not work with Railway’s sync API. Use an account or workspace token.
|
|
27
|
+
|
|
28
|
+
### 2. Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install -g @akeyless-community/railway-sync
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or clone and run locally:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/akeyless-community/railway-akeyless-sync.git
|
|
38
|
+
cd railway-akeyless-sync
|
|
39
|
+
npm install
|
|
40
|
+
cp .env.example .env
|
|
41
|
+
# Edit .env
|
|
42
|
+
npm run sync
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 3. Configure
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
export AKEYLESS_ACCESS_ID="p-..."
|
|
49
|
+
export AKEYLESS_ACCESS_KEY="..."
|
|
50
|
+
export AKEYLESS_SECRET_PATH="/railway/my-project/production"
|
|
51
|
+
export RAILWAY_API_TOKEN="..."
|
|
52
|
+
export RAILWAY_PROJECT_ID="..."
|
|
53
|
+
export RAILWAY_ENVIRONMENT_ID="..."
|
|
54
|
+
export RAILWAY_SERVICE_ID="..." # optional — omit for shared variables
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 4. Sync
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Preview
|
|
61
|
+
akeyless-railway-sync sync --dry-run
|
|
62
|
+
|
|
63
|
+
# Apply
|
|
64
|
+
akeyless-railway-sync sync
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## GitHub Action
|
|
68
|
+
|
|
69
|
+
Add [`.github/workflows/sync-secrets.yml`](./examples/github-workflow/sync-secrets.yml):
|
|
70
|
+
|
|
71
|
+
```yaml
|
|
72
|
+
name: Sync secrets to Railway
|
|
73
|
+
|
|
74
|
+
on:
|
|
75
|
+
schedule:
|
|
76
|
+
- cron: "0 */6 * * *"
|
|
77
|
+
workflow_dispatch:
|
|
78
|
+
|
|
79
|
+
jobs:
|
|
80
|
+
sync:
|
|
81
|
+
runs-on: ubuntu-latest
|
|
82
|
+
steps:
|
|
83
|
+
- uses: actions/checkout@v4
|
|
84
|
+
|
|
85
|
+
- uses: akeyless-community/railway-akeyless-sync/action@v1
|
|
86
|
+
with:
|
|
87
|
+
akeyless-access-id: ${{ secrets.AKEYLESS_ACCESS_ID }}
|
|
88
|
+
akeyless-access-key: ${{ secrets.AKEYLESS_ACCESS_KEY }}
|
|
89
|
+
akeyless-secret-path: /railway/my-project/production
|
|
90
|
+
railway-api-token: ${{ secrets.RAILWAY_API_TOKEN }}
|
|
91
|
+
railway-project-id: ${{ secrets.RAILWAY_PROJECT_ID }}
|
|
92
|
+
railway-environment-id: ${{ secrets.RAILWAY_ENVIRONMENT_ID }}
|
|
93
|
+
railway-service-id: ${{ secrets.RAILWAY_SERVICE_ID }}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### GitHub secrets to configure
|
|
97
|
+
|
|
98
|
+
| Secret | Description |
|
|
99
|
+
|--------|-------------|
|
|
100
|
+
| `AKEYLESS_ACCESS_ID` | Akeyless access ID (read-only on sync path) |
|
|
101
|
+
| `AKEYLESS_ACCESS_KEY` | Akeyless access key |
|
|
102
|
+
| `RAILWAY_API_TOKEN` | Railway account/workspace token |
|
|
103
|
+
| `RAILWAY_PROJECT_ID` | Target project ID |
|
|
104
|
+
| `RAILWAY_ENVIRONMENT_ID` | Target environment ID |
|
|
105
|
+
| `RAILWAY_SERVICE_ID` | Optional service ID |
|
|
106
|
+
|
|
107
|
+
## Secret naming
|
|
108
|
+
|
|
109
|
+
| Akeyless path | Railway variable |
|
|
110
|
+
|---------------|------------------|
|
|
111
|
+
| `/railway/my-project/production/database-url` | `DATABASE_URL` |
|
|
112
|
+
| `/railway/my-project/production/stripe-secret-key` | `STRIPE_SECRET_KEY` |
|
|
113
|
+
|
|
114
|
+
Rules:
|
|
115
|
+
- Folder path is stripped; only the item name is used
|
|
116
|
+
- Non-alphanumeric characters become underscores
|
|
117
|
+
- Names are uppercased
|
|
118
|
+
- `RAILWAY_*` variables are never overwritten (Railway-provided)
|
|
119
|
+
- Reference variables (`${{ Service.VAR }}`) are skipped by default
|
|
120
|
+
|
|
121
|
+
## Configuration reference
|
|
122
|
+
|
|
123
|
+
| Variable | Default | Description |
|
|
124
|
+
|----------|---------|-------------|
|
|
125
|
+
| `DELETE_ORPHANED` | `false` | Remove Railway vars not in Akeyless |
|
|
126
|
+
| `SKIP_DEPLOYS` | `false` | Pass `skipDeploys` to Railway API |
|
|
127
|
+
| `REPLACE_ALL` | `false` | Replace entire variable set (dangerous) |
|
|
128
|
+
| `SKIP_RAILWAY_PREFIX` | `true` | Never sync `RAILWAY_*` names |
|
|
129
|
+
| `SKIP_REFERENCE_VARIABLES` | `true` | Skip existing `${{ … }}` references |
|
|
130
|
+
|
|
131
|
+
## Push sync vs runtime pull
|
|
132
|
+
|
|
133
|
+
| Pattern | Tool |
|
|
134
|
+
|---------|------|
|
|
135
|
+
| **Push sync** (this repo) | Secrets copied into Railway variables |
|
|
136
|
+
| **Runtime pull** | [`@akeyless-community/railway-runtime`](https://github.com/akeyless-community/railway-runtime) — app fetches at startup |
|
|
137
|
+
|
|
138
|
+
## Related projects
|
|
139
|
+
|
|
140
|
+
- [railway-runtime](https://github.com/akeyless-community/railway-runtime) — fetch secrets at runtime on Railway
|
|
141
|
+
- [supabase-akeyless-integration](https://github.com/akeyless-community/supabase-akeyless-integration) — same push-sync pattern for Supabase
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
Apache-2.0
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
name: Akeyless Railway Sync
|
|
2
|
+
description: Sync secrets from Akeyless to Railway environment variables
|
|
3
|
+
branding:
|
|
4
|
+
icon: train
|
|
5
|
+
color: purple
|
|
6
|
+
|
|
7
|
+
inputs:
|
|
8
|
+
akeyless-access-id:
|
|
9
|
+
description: Akeyless access ID
|
|
10
|
+
required: true
|
|
11
|
+
akeyless-access-key:
|
|
12
|
+
description: Akeyless access key
|
|
13
|
+
required: true
|
|
14
|
+
akeyless-secret-path:
|
|
15
|
+
description: Akeyless folder path containing secrets to sync
|
|
16
|
+
required: true
|
|
17
|
+
default: /
|
|
18
|
+
akeyless-api-url:
|
|
19
|
+
description: Akeyless API URL
|
|
20
|
+
required: false
|
|
21
|
+
default: https://api.akeyless.io
|
|
22
|
+
railway-api-token:
|
|
23
|
+
description: Railway account or workspace API token
|
|
24
|
+
required: true
|
|
25
|
+
railway-project-id:
|
|
26
|
+
description: Railway project ID
|
|
27
|
+
required: true
|
|
28
|
+
railway-environment-id:
|
|
29
|
+
description: Railway environment ID
|
|
30
|
+
required: true
|
|
31
|
+
railway-service-id:
|
|
32
|
+
description: Railway service ID (omit for shared environment variables)
|
|
33
|
+
required: false
|
|
34
|
+
default: ""
|
|
35
|
+
delete-orphaned:
|
|
36
|
+
description: Delete Railway variables not present in Akeyless
|
|
37
|
+
required: false
|
|
38
|
+
default: "false"
|
|
39
|
+
skip-deploys:
|
|
40
|
+
description: Do not trigger Railway redeploys when updating variables
|
|
41
|
+
required: false
|
|
42
|
+
default: "false"
|
|
43
|
+
dry-run:
|
|
44
|
+
description: Preview changes without writing to Railway
|
|
45
|
+
required: false
|
|
46
|
+
default: "false"
|
|
47
|
+
|
|
48
|
+
runs:
|
|
49
|
+
using: composite
|
|
50
|
+
steps:
|
|
51
|
+
- name: Setup Node.js
|
|
52
|
+
uses: actions/setup-node@v4
|
|
53
|
+
with:
|
|
54
|
+
node-version: "20"
|
|
55
|
+
|
|
56
|
+
- name: Install sync CLI
|
|
57
|
+
shell: bash
|
|
58
|
+
run: npm install -g github:akeyless-community/railway-akeyless-sync
|
|
59
|
+
|
|
60
|
+
- name: Sync secrets
|
|
61
|
+
shell: bash
|
|
62
|
+
env:
|
|
63
|
+
AKEYLESS_ACCESS_ID: ${{ inputs.akeyless-access-id }}
|
|
64
|
+
AKEYLESS_ACCESS_KEY: ${{ inputs.akeyless-access-key }}
|
|
65
|
+
AKEYLESS_SECRET_PATH: ${{ inputs.akeyless-secret-path }}
|
|
66
|
+
AKEYLESS_API_URL: ${{ inputs.akeyless-api-url }}
|
|
67
|
+
RAILWAY_API_TOKEN: ${{ inputs.railway-api-token }}
|
|
68
|
+
RAILWAY_PROJECT_ID: ${{ inputs.railway-project-id }}
|
|
69
|
+
RAILWAY_ENVIRONMENT_ID: ${{ inputs.railway-environment-id }}
|
|
70
|
+
RAILWAY_SERVICE_ID: ${{ inputs.railway-service-id }}
|
|
71
|
+
DELETE_ORPHANED: ${{ inputs.delete-orphaned }}
|
|
72
|
+
SKIP_DEPLOYS: ${{ inputs.skip-deploys }}
|
|
73
|
+
run: |
|
|
74
|
+
ARGS="sync"
|
|
75
|
+
if [ "${{ inputs.dry-run }}" = "true" ]; then
|
|
76
|
+
ARGS="$ARGS --dry-run"
|
|
77
|
+
fi
|
|
78
|
+
akeyless-railway-sync $ARGS
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class AkeylessClient {
|
|
2
|
+
private readonly apiUrl;
|
|
3
|
+
private readonly accessId?;
|
|
4
|
+
private readonly accessKey?;
|
|
5
|
+
private token?;
|
|
6
|
+
constructor(apiUrl: string, accessId?: string | undefined, accessKey?: string | undefined, initialToken?: string);
|
|
7
|
+
authenticate(): Promise<string>;
|
|
8
|
+
listStaticSecrets(path: string): Promise<string[]>;
|
|
9
|
+
getSecretValues(names: string[]): Promise<Record<string, string>>;
|
|
10
|
+
private walk;
|
|
11
|
+
private post;
|
|
12
|
+
}
|
package/dist/akeyless.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export class AkeylessClient {
|
|
2
|
+
apiUrl;
|
|
3
|
+
accessId;
|
|
4
|
+
accessKey;
|
|
5
|
+
token;
|
|
6
|
+
constructor(apiUrl, accessId, accessKey, initialToken) {
|
|
7
|
+
this.apiUrl = apiUrl;
|
|
8
|
+
this.accessId = accessId;
|
|
9
|
+
this.accessKey = accessKey;
|
|
10
|
+
this.token = initialToken;
|
|
11
|
+
}
|
|
12
|
+
async authenticate() {
|
|
13
|
+
if (this.token)
|
|
14
|
+
return this.token;
|
|
15
|
+
if (!this.accessId || !this.accessKey) {
|
|
16
|
+
throw new Error("Akeyless credentials are required");
|
|
17
|
+
}
|
|
18
|
+
const response = await this.post("/auth", {
|
|
19
|
+
"access-id": this.accessId,
|
|
20
|
+
"access-key": this.accessKey,
|
|
21
|
+
});
|
|
22
|
+
this.token = response.token;
|
|
23
|
+
return this.token;
|
|
24
|
+
}
|
|
25
|
+
async listStaticSecrets(path) {
|
|
26
|
+
await this.authenticate();
|
|
27
|
+
const names = [];
|
|
28
|
+
await this.walk(path, names);
|
|
29
|
+
return names.filter((name) => !name.endsWith("/"));
|
|
30
|
+
}
|
|
31
|
+
async getSecretValues(names) {
|
|
32
|
+
if (names.length === 0)
|
|
33
|
+
return {};
|
|
34
|
+
await this.authenticate();
|
|
35
|
+
const response = await this.post("/get-secret-value", {
|
|
36
|
+
names,
|
|
37
|
+
json: true,
|
|
38
|
+
});
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
async walk(path, names) {
|
|
42
|
+
const normalized = path.endsWith("/") ? path.slice(0, -1) : path;
|
|
43
|
+
const response = await this.post("/list-items", {
|
|
44
|
+
path: normalized || "/",
|
|
45
|
+
type: ["static-secret"],
|
|
46
|
+
"auto-pagination": "enabled",
|
|
47
|
+
});
|
|
48
|
+
for (const item of response.items ?? []) {
|
|
49
|
+
if (item.item_type === "STATIC_SECRET") {
|
|
50
|
+
names.push(item.item_name);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (const folder of response.folders ?? []) {
|
|
54
|
+
await this.walk(folder, names);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async post(endpoint, body) {
|
|
58
|
+
const response = await fetch(`${this.apiUrl}${endpoint}`, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: { "Content-Type": "application/json" },
|
|
61
|
+
body: JSON.stringify({ ...body, token: this.token }),
|
|
62
|
+
});
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
const text = await response.text();
|
|
65
|
+
throw new Error(`Akeyless ${endpoint} failed (${response.status}): ${text}`);
|
|
66
|
+
}
|
|
67
|
+
return (await response.json());
|
|
68
|
+
}
|
|
69
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { config as loadEnvFile } from "dotenv";
|
|
3
|
+
loadEnvFile();
|
|
4
|
+
import { loadConfig } from "./config.js";
|
|
5
|
+
import { runSyncFromEnv } from "./index.js";
|
|
6
|
+
function printResult(result) {
|
|
7
|
+
console.log("\nAkeyless to Railway sync complete\n");
|
|
8
|
+
console.log(` Created: ${result.created.length}`);
|
|
9
|
+
console.log(` Updated: ${result.updated.length}`);
|
|
10
|
+
console.log(` Skipped: ${result.skipped.length}`);
|
|
11
|
+
console.log(` Deleted: ${result.deleted.length}`);
|
|
12
|
+
console.log(` Errors: ${result.errors.length}`);
|
|
13
|
+
if (result.created.length) {
|
|
14
|
+
console.log("\nCreated:");
|
|
15
|
+
for (const name of result.created)
|
|
16
|
+
console.log(` + ${name}`);
|
|
17
|
+
}
|
|
18
|
+
if (result.updated.length) {
|
|
19
|
+
console.log("\nUpdated:");
|
|
20
|
+
for (const name of result.updated)
|
|
21
|
+
console.log(` ~ ${name}`);
|
|
22
|
+
}
|
|
23
|
+
if (result.skipped.length) {
|
|
24
|
+
console.log("\nSkipped:");
|
|
25
|
+
for (const name of result.skipped)
|
|
26
|
+
console.log(` - ${name}`);
|
|
27
|
+
}
|
|
28
|
+
if (result.deleted.length) {
|
|
29
|
+
console.log("\nDeleted:");
|
|
30
|
+
for (const name of result.deleted)
|
|
31
|
+
console.log(` x ${name}`);
|
|
32
|
+
}
|
|
33
|
+
if (result.errors.length) {
|
|
34
|
+
console.log("\nErrors:");
|
|
35
|
+
for (const error of result.errors) {
|
|
36
|
+
console.log(` ! ${error.name}: ${error.error}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function main() {
|
|
41
|
+
const [command, ...args] = process.argv.slice(2);
|
|
42
|
+
if (!command || command === "help" || command === "--help") {
|
|
43
|
+
console.log(`Akeyless Railway Sync
|
|
44
|
+
|
|
45
|
+
Usage:
|
|
46
|
+
akeyless-railway-sync sync [--dry-run]
|
|
47
|
+
akeyless-railway-sync validate
|
|
48
|
+
|
|
49
|
+
Environment variables (shell or .env file):
|
|
50
|
+
AKEYLESS_ACCESS_ID, AKEYLESS_ACCESS_KEY (or AKEYLESS_TOKEN)
|
|
51
|
+
AKEYLESS_SECRET_PATH (default: /)
|
|
52
|
+
RAILWAY_API_TOKEN (account or workspace token)
|
|
53
|
+
RAILWAY_PROJECT_ID
|
|
54
|
+
RAILWAY_ENVIRONMENT_ID
|
|
55
|
+
RAILWAY_SERVICE_ID (optional — omit for shared variables)
|
|
56
|
+
DELETE_ORPHANED (default: false)
|
|
57
|
+
SKIP_DEPLOYS (default: false)
|
|
58
|
+
REPLACE_ALL (default: false — dangerous)
|
|
59
|
+
`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (command === "validate") {
|
|
63
|
+
loadConfig();
|
|
64
|
+
console.log("Configuration is valid.");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (command === "sync") {
|
|
68
|
+
const dryRun = args.includes("--dry-run");
|
|
69
|
+
const result = await runSyncFromEnv({ dryRun });
|
|
70
|
+
printResult(result);
|
|
71
|
+
if (result.errors.length > 0) {
|
|
72
|
+
process.exitCode = 1;
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
console.error(`Unknown command: ${command}`);
|
|
77
|
+
process.exitCode = 1;
|
|
78
|
+
}
|
|
79
|
+
main().catch((error) => {
|
|
80
|
+
console.error(`Error: ${error.message}`);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
});
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SyncConfig } from "./types.js";
|
|
2
|
+
export declare function toEnvName(itemPath: string, prefix?: string): string;
|
|
3
|
+
export declare function isProtectedRailwayVariable(name: string, value: string, options: {
|
|
4
|
+
skipRailwayPrefix: boolean;
|
|
5
|
+
skipReferenceVariables: boolean;
|
|
6
|
+
}): string | undefined;
|
|
7
|
+
export declare function loadConfig(overrides?: Partial<SyncConfig>): SyncConfig;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
function env(name) {
|
|
2
|
+
const value = process.env[name];
|
|
3
|
+
return value && value.length > 0 ? value : undefined;
|
|
4
|
+
}
|
|
5
|
+
function requireEnv(name) {
|
|
6
|
+
const value = env(name);
|
|
7
|
+
if (!value) {
|
|
8
|
+
throw new Error(`Missing required environment variable: ${name}. ` +
|
|
9
|
+
"Set it in your shell or create a .env file (see .env.example).");
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function parseBoolean(name, defaultValue) {
|
|
14
|
+
const value = env(name);
|
|
15
|
+
if (value === undefined) {
|
|
16
|
+
return defaultValue;
|
|
17
|
+
}
|
|
18
|
+
return value === "true" || value === "1" || value === "yes";
|
|
19
|
+
}
|
|
20
|
+
function validateRailwayToken(token) {
|
|
21
|
+
const trimmed = token.trim();
|
|
22
|
+
if (trimmed.length < 20) {
|
|
23
|
+
throw new Error("RAILWAY_API_TOKEN looks too short. Use an account or workspace token from " +
|
|
24
|
+
"https://railway.com/account/tokens (project-scoped tokens are not supported for sync).");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function toEnvName(itemPath, prefix) {
|
|
28
|
+
const base = itemPath.split("/").pop() ?? itemPath;
|
|
29
|
+
let name = base.replace(/[^a-zA-Z0-9_]/g, "_").toUpperCase();
|
|
30
|
+
if (prefix && name.startsWith(prefix)) {
|
|
31
|
+
name = name.slice(prefix.length);
|
|
32
|
+
}
|
|
33
|
+
return name;
|
|
34
|
+
}
|
|
35
|
+
export function isProtectedRailwayVariable(name, value, options) {
|
|
36
|
+
if (options.skipRailwayPrefix && name.startsWith("RAILWAY_")) {
|
|
37
|
+
return "RAILWAY_ prefix is reserved by Railway";
|
|
38
|
+
}
|
|
39
|
+
if (options.skipReferenceVariables && value.includes("${{")) {
|
|
40
|
+
return "reference variables are managed by Railway";
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
export function loadConfig(overrides = {}) {
|
|
45
|
+
const railwayApiToken = requireEnv("RAILWAY_API_TOKEN").trim();
|
|
46
|
+
validateRailwayToken(railwayApiToken);
|
|
47
|
+
const config = {
|
|
48
|
+
akeylessAccessId: env("AKEYLESS_ACCESS_ID"),
|
|
49
|
+
akeylessAccessKey: env("AKEYLESS_ACCESS_KEY"),
|
|
50
|
+
akeylessToken: env("AKEYLESS_TOKEN"),
|
|
51
|
+
akeylessApiUrl: env("AKEYLESS_API_URL") ?? "https://api.akeyless.io",
|
|
52
|
+
akeylessSecretPath: env("AKEYLESS_SECRET_PATH") ?? "/",
|
|
53
|
+
railwayApiToken,
|
|
54
|
+
railwayProjectId: requireEnv("RAILWAY_PROJECT_ID").trim(),
|
|
55
|
+
railwayEnvironmentId: requireEnv("RAILWAY_ENVIRONMENT_ID").trim(),
|
|
56
|
+
railwayServiceId: env("RAILWAY_SERVICE_ID")?.trim(),
|
|
57
|
+
secretNamePrefix: env("SECRET_NAME_PREFIX"),
|
|
58
|
+
skipRailwayPrefix: parseBoolean("SKIP_RAILWAY_PREFIX", true),
|
|
59
|
+
skipReferenceVariables: parseBoolean("SKIP_REFERENCE_VARIABLES", true),
|
|
60
|
+
deleteOrphaned: parseBoolean("DELETE_ORPHANED", false),
|
|
61
|
+
skipDeploys: parseBoolean("SKIP_DEPLOYS", false),
|
|
62
|
+
replaceAll: parseBoolean("REPLACE_ALL", false),
|
|
63
|
+
dryRun: false,
|
|
64
|
+
...overrides,
|
|
65
|
+
};
|
|
66
|
+
if (!config.akeylessToken && (!config.akeylessAccessId || !config.akeylessAccessKey)) {
|
|
67
|
+
throw new Error("Provide AKEYLESS_TOKEN or both AKEYLESS_ACCESS_ID and AKEYLESS_ACCESS_KEY " +
|
|
68
|
+
"(in your shell or .env file).");
|
|
69
|
+
}
|
|
70
|
+
return config;
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { isProtectedRailwayVariable, toEnvName } from "./config.js";
|
|
4
|
+
test("toEnvName strips folder path and uppercases", () => {
|
|
5
|
+
assert.equal(toEnvName("/railway/demo/production/database-url"), "DATABASE_URL");
|
|
6
|
+
});
|
|
7
|
+
test("toEnvName strips configured prefix", () => {
|
|
8
|
+
assert.equal(toEnvName("/railway/demo/STRIPE_KEY", "STRIPE_"), "KEY");
|
|
9
|
+
});
|
|
10
|
+
test("isProtectedRailwayVariable blocks RAILWAY_ names", () => {
|
|
11
|
+
assert.equal(isProtectedRailwayVariable("RAILWAY_PUBLIC_DOMAIN", "example.com", {
|
|
12
|
+
skipRailwayPrefix: true,
|
|
13
|
+
skipReferenceVariables: true,
|
|
14
|
+
}), "RAILWAY_ prefix is reserved by Railway");
|
|
15
|
+
});
|
|
16
|
+
test("isProtectedRailwayVariable blocks reference syntax", () => {
|
|
17
|
+
assert.equal(isProtectedRailwayVariable("DATABASE_URL", "${{ Postgres.DATABASE_URL }}", {
|
|
18
|
+
skipRailwayPrefix: true,
|
|
19
|
+
skipReferenceVariables: true,
|
|
20
|
+
}), "reference variables are managed by Railway");
|
|
21
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AkeylessClient } from "./akeyless.js";
|
|
2
|
+
import { loadConfig } from "./config.js";
|
|
3
|
+
import { RailwayVariablesClient } from "./railway.js";
|
|
4
|
+
import type { SyncConfig, SyncResult } from "./types.js";
|
|
5
|
+
export declare function syncSecrets(config: SyncConfig): Promise<SyncResult>;
|
|
6
|
+
export declare function runSyncFromEnv(overrides?: Partial<SyncConfig>): Promise<SyncResult>;
|
|
7
|
+
export { loadConfig, AkeylessClient, RailwayVariablesClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { AkeylessClient } from "./akeyless.js";
|
|
2
|
+
import { isProtectedRailwayVariable, loadConfig, toEnvName } from "./config.js";
|
|
3
|
+
import { RailwayVariablesClient } from "./railway.js";
|
|
4
|
+
export async function syncSecrets(config) {
|
|
5
|
+
const result = {
|
|
6
|
+
created: [],
|
|
7
|
+
updated: [],
|
|
8
|
+
skipped: [],
|
|
9
|
+
deleted: [],
|
|
10
|
+
errors: [],
|
|
11
|
+
};
|
|
12
|
+
const akeyless = new AkeylessClient(config.akeylessApiUrl, config.akeylessAccessId, config.akeylessAccessKey, config.akeylessToken);
|
|
13
|
+
const railway = new RailwayVariablesClient(config.railwayApiToken);
|
|
14
|
+
const target = {
|
|
15
|
+
projectId: config.railwayProjectId,
|
|
16
|
+
environmentId: config.railwayEnvironmentId,
|
|
17
|
+
serviceId: config.railwayServiceId,
|
|
18
|
+
};
|
|
19
|
+
const itemNames = await akeyless.listStaticSecrets(config.akeylessSecretPath);
|
|
20
|
+
const values = await akeyless.getSecretValues(itemNames);
|
|
21
|
+
const existing = await railway.listVariables(target);
|
|
22
|
+
const existingNames = new Set(Object.keys(existing));
|
|
23
|
+
const desired = new Map();
|
|
24
|
+
for (const itemName of itemNames) {
|
|
25
|
+
const envName = toEnvName(itemName, config.secretNamePrefix);
|
|
26
|
+
const value = values[itemName];
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
result.errors.push({ name: itemName, error: "Secret value not returned by Akeyless" });
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const skipReason = isProtectedRailwayVariable(envName, value, {
|
|
32
|
+
skipRailwayPrefix: config.skipRailwayPrefix,
|
|
33
|
+
skipReferenceVariables: config.skipReferenceVariables,
|
|
34
|
+
});
|
|
35
|
+
if (skipReason) {
|
|
36
|
+
result.skipped.push(`${itemName} -> ${envName} (${skipReason})`);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
desired.set(envName, value);
|
|
40
|
+
}
|
|
41
|
+
const toUpsert = Object.fromEntries(desired.entries());
|
|
42
|
+
if (config.dryRun) {
|
|
43
|
+
for (const name of Object.keys(toUpsert)) {
|
|
44
|
+
if (existingNames.has(name)) {
|
|
45
|
+
result.updated.push(name);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
result.created.push(name);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (config.deleteOrphaned) {
|
|
52
|
+
for (const name of Object.keys(existing)) {
|
|
53
|
+
if (!desired.has(name)) {
|
|
54
|
+
const skipReason = isProtectedRailwayVariable(name, existing[name] ?? "", {
|
|
55
|
+
skipRailwayPrefix: config.skipRailwayPrefix,
|
|
56
|
+
skipReferenceVariables: config.skipReferenceVariables,
|
|
57
|
+
});
|
|
58
|
+
if (!skipReason) {
|
|
59
|
+
result.deleted.push(name);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
await railway.upsertVariables(target, toUpsert, {
|
|
68
|
+
skipDeploys: config.skipDeploys,
|
|
69
|
+
replace: config.replaceAll,
|
|
70
|
+
});
|
|
71
|
+
for (const name of Object.keys(toUpsert)) {
|
|
72
|
+
if (existingNames.has(name)) {
|
|
73
|
+
result.updated.push(name);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
result.created.push(name);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw new Error(`Sync failed while upserting Railway variables: ${error.message}`);
|
|
82
|
+
}
|
|
83
|
+
if (config.deleteOrphaned && !config.replaceAll) {
|
|
84
|
+
const managedNames = new Set(desired.keys());
|
|
85
|
+
const orphaned = Object.keys(existing).filter((name) => {
|
|
86
|
+
if (managedNames.has(name)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const skipReason = isProtectedRailwayVariable(name, existing[name] ?? "", {
|
|
90
|
+
skipRailwayPrefix: config.skipRailwayPrefix,
|
|
91
|
+
skipReferenceVariables: config.skipReferenceVariables,
|
|
92
|
+
});
|
|
93
|
+
return !skipReason;
|
|
94
|
+
});
|
|
95
|
+
for (const name of orphaned) {
|
|
96
|
+
try {
|
|
97
|
+
await railway.deleteVariable(target, name, { skipDeploys: config.skipDeploys });
|
|
98
|
+
result.deleted.push(name);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
result.errors.push({
|
|
102
|
+
name,
|
|
103
|
+
error: `Failed to delete orphaned variable: ${error.message}`,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
export async function runSyncFromEnv(overrides = {}) {
|
|
111
|
+
const config = loadConfig(overrides);
|
|
112
|
+
return syncSecrets(config);
|
|
113
|
+
}
|
|
114
|
+
export { loadConfig, AkeylessClient, RailwayVariablesClient };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface RailwayVariableTarget {
|
|
2
|
+
projectId: string;
|
|
3
|
+
environmentId: string;
|
|
4
|
+
serviceId?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class RailwayVariablesClient {
|
|
7
|
+
private readonly apiToken;
|
|
8
|
+
constructor(apiToken: string);
|
|
9
|
+
listVariables(target: RailwayVariableTarget): Promise<Record<string, string>>;
|
|
10
|
+
upsertVariables(target: RailwayVariableTarget, variables: Record<string, string>, options?: {
|
|
11
|
+
skipDeploys?: boolean;
|
|
12
|
+
replace?: boolean;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
deleteVariable(target: RailwayVariableTarget, name: string, options?: {
|
|
15
|
+
skipDeploys?: boolean;
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
private graphql;
|
|
18
|
+
}
|
package/dist/railway.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const RAILWAY_GRAPHQL_URL = "https://backboard.railway.com/graphql/v2";
|
|
2
|
+
export class RailwayVariablesClient {
|
|
3
|
+
apiToken;
|
|
4
|
+
constructor(apiToken) {
|
|
5
|
+
this.apiToken = apiToken;
|
|
6
|
+
}
|
|
7
|
+
async listVariables(target) {
|
|
8
|
+
const data = await this.graphql(`query Variables($projectId: String!, $environmentId: String!, $serviceId: String) {
|
|
9
|
+
variables(projectId: $projectId, environmentId: $environmentId, serviceId: $serviceId)
|
|
10
|
+
}`, {
|
|
11
|
+
projectId: target.projectId,
|
|
12
|
+
environmentId: target.environmentId,
|
|
13
|
+
serviceId: target.serviceId ?? null,
|
|
14
|
+
});
|
|
15
|
+
return data.variables ?? {};
|
|
16
|
+
}
|
|
17
|
+
async upsertVariables(target, variables, options = {}) {
|
|
18
|
+
if (Object.keys(variables).length === 0) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
await this.graphql(`mutation VariableCollectionUpsert($input: VariableCollectionUpsertInput!) {
|
|
22
|
+
variableCollectionUpsert(input: $input)
|
|
23
|
+
}`, {
|
|
24
|
+
input: {
|
|
25
|
+
projectId: target.projectId,
|
|
26
|
+
environmentId: target.environmentId,
|
|
27
|
+
serviceId: target.serviceId ?? null,
|
|
28
|
+
variables,
|
|
29
|
+
skipDeploys: options.skipDeploys ?? false,
|
|
30
|
+
replace: options.replace ?? false,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async deleteVariable(target, name, options = {}) {
|
|
35
|
+
await this.graphql(`mutation VariableDelete($input: VariableDeleteInput!) {
|
|
36
|
+
variableDelete(input: $input)
|
|
37
|
+
}`, {
|
|
38
|
+
input: {
|
|
39
|
+
projectId: target.projectId,
|
|
40
|
+
environmentId: target.environmentId,
|
|
41
|
+
serviceId: target.serviceId ?? null,
|
|
42
|
+
name,
|
|
43
|
+
skipDeploys: options.skipDeploys ?? false,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async graphql(query, variables) {
|
|
48
|
+
const response = await fetch(RAILWAY_GRAPHQL_URL, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: {
|
|
51
|
+
Authorization: `Bearer ${this.apiToken}`,
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
},
|
|
54
|
+
body: JSON.stringify({ query, variables }),
|
|
55
|
+
});
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
const text = await response.text();
|
|
58
|
+
throw new Error(`Railway GraphQL failed (${response.status}): ${text}`);
|
|
59
|
+
}
|
|
60
|
+
const payload = (await response.json());
|
|
61
|
+
if (payload.errors?.length) {
|
|
62
|
+
const message = payload.errors.map((error) => error.message).join("; ");
|
|
63
|
+
throw new Error(`Railway GraphQL error: ${message}`);
|
|
64
|
+
}
|
|
65
|
+
if (!payload.data) {
|
|
66
|
+
throw new Error("Railway GraphQL returned no data");
|
|
67
|
+
}
|
|
68
|
+
return payload.data;
|
|
69
|
+
}
|
|
70
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface SyncConfig {
|
|
2
|
+
akeylessAccessId?: string;
|
|
3
|
+
akeylessAccessKey?: string;
|
|
4
|
+
akeylessToken?: string;
|
|
5
|
+
akeylessApiUrl: string;
|
|
6
|
+
akeylessSecretPath: string;
|
|
7
|
+
railwayApiToken: string;
|
|
8
|
+
railwayProjectId: string;
|
|
9
|
+
railwayEnvironmentId: string;
|
|
10
|
+
railwayServiceId?: string;
|
|
11
|
+
secretNamePrefix?: string;
|
|
12
|
+
skipRailwayPrefix: boolean;
|
|
13
|
+
skipReferenceVariables: boolean;
|
|
14
|
+
deleteOrphaned: boolean;
|
|
15
|
+
skipDeploys: boolean;
|
|
16
|
+
replaceAll: boolean;
|
|
17
|
+
dryRun: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface AkeylessItem {
|
|
20
|
+
item_name: string;
|
|
21
|
+
item_type: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AkeylessListResponse {
|
|
24
|
+
items: AkeylessItem[] | null;
|
|
25
|
+
folders: string[] | null;
|
|
26
|
+
}
|
|
27
|
+
export interface SyncResult {
|
|
28
|
+
created: string[];
|
|
29
|
+
updated: string[];
|
|
30
|
+
skipped: string[];
|
|
31
|
+
deleted: string[];
|
|
32
|
+
errors: Array<{
|
|
33
|
+
name: string;
|
|
34
|
+
error: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: Sync secrets to Railway
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
schedule:
|
|
5
|
+
- cron: "0 */6 * * *"
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
sync:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
|
|
14
|
+
- uses: akeyless-community/railway-akeyless-sync/action@v1
|
|
15
|
+
with:
|
|
16
|
+
akeyless-access-id: ${{ secrets.AKEYLESS_ACCESS_ID }}
|
|
17
|
+
akeyless-access-key: ${{ secrets.AKEYLESS_ACCESS_KEY }}
|
|
18
|
+
akeyless-secret-path: /railway/my-project/production
|
|
19
|
+
railway-api-token: ${{ secrets.RAILWAY_API_TOKEN }}
|
|
20
|
+
railway-project-id: ${{ secrets.RAILWAY_PROJECT_ID }}
|
|
21
|
+
railway-environment-id: ${{ secrets.RAILWAY_ENVIRONMENT_ID }}
|
|
22
|
+
railway-service-id: ${{ secrets.RAILWAY_SERVICE_ID }}
|
|
23
|
+
skip-deploys: "false"
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@akeyless-community/railway-sync",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Sync secrets from Akeyless to Railway service or shared environment variables",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "Akeyless Community",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/akeyless-community/railway-akeyless-sync.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/akeyless-community/railway-akeyless-sync#readme",
|
|
13
|
+
"bin": {
|
|
14
|
+
"akeyless-railway-sync": "bin/akeyless-railway-sync.js"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"bin",
|
|
20
|
+
"action",
|
|
21
|
+
"examples"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"dev": "tsx src/cli.ts",
|
|
26
|
+
"sync": "tsx src/cli.ts sync",
|
|
27
|
+
"lint": "tsc --noEmit",
|
|
28
|
+
"test": "node --import tsx --test src/*.test.ts",
|
|
29
|
+
"prepublishOnly": "npm run build && npm test"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"akeyless",
|
|
33
|
+
"railway",
|
|
34
|
+
"secrets",
|
|
35
|
+
"sync",
|
|
36
|
+
"github-actions",
|
|
37
|
+
"devops"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"dotenv": "^16.4.7"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^22.10.0",
|
|
50
|
+
"tsx": "^4.19.2",
|
|
51
|
+
"typescript": "^5.7.2"
|
|
52
|
+
}
|
|
53
|
+
}
|