jwt_auth_cognito 1.0.0.pre.beta.3 → 1.0.0.pre.beta.5
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +34 -1
- data/CLAUDE.md +79 -49
- data/README.md +199 -11
- data/bitbucket-pipelines.yml +17 -15
- data/jwt_auth_cognito.gemspec +0 -2
- data/lib/jwt_auth_cognito/configuration.rb +3 -6
- data/lib/jwt_auth_cognito/jwt_validator.rb +0 -79
- data/lib/jwt_auth_cognito/redis_service.rb +30 -9
- data/lib/jwt_auth_cognito/ssm_service.rb +24 -3
- data/lib/jwt_auth_cognito/version.rb +1 -1
- metadata +2 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81416775877402a8d73ccc1404f223f8210f6fb757c3b9193c73718c81260dd7
|
4
|
+
data.tar.gz: 89700ce4cbe9518ab25586b22f0ab46a315d60dd03e267e78c47b729d0641e9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa00db084bed24d06c72f102332b453b561bb7dc8dd45e3b77d7caea097446dab1f292edac92b725da5b1ebd8e949a80b2b69ee4359fa6707b44a9b93c7af74b
|
7
|
+
data.tar.gz: be08d9bea8482431b5df5c4d40ea32f450d25e8136cb66c3d8b80b18902c06b802c77645edbc2f7e0b6cc8ca58003530b5ef9fdb33ef65e392c9c6a4e3840df3
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [1.0.0-beta.5] - 2025-01-22
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
|
14
|
+
- **RubyGems Deployment Pipeline**: Fixed CI/CD deployment issues
|
15
|
+
- Removed MFA requirement that was blocking automated deployment
|
16
|
+
- Fixed credentials YAML format using `printf` to avoid parsing conflicts
|
17
|
+
- Removed unnecessary openssl dependency (part of Ruby stdlib)
|
18
|
+
- Updated pipeline to use correct `:rubygems_api_key:` format for credentials
|
19
|
+
|
20
|
+
- **API Key Validation**: Added missing Redis methods for ApiKeyValidator
|
21
|
+
- Added generic `get()` and `set()` methods to RedisService
|
22
|
+
- Methods include proper error handling with BlacklistError exceptions
|
23
|
+
- Support for TTL parameter in set() method using setex
|
24
|
+
- Resolves "undefined method `get` for RedisService" error
|
25
|
+
|
26
|
+
### Improved
|
27
|
+
|
28
|
+
- **Code Quality**: Enhanced test coverage and documentation
|
29
|
+
- Added comprehensive tests for new Redis methods
|
30
|
+
- All tests passing (74 examples, 0 failures)
|
31
|
+
- RuboCop compliance maintained
|
32
|
+
- Updated CLAUDE.md with correct deployment procedures
|
33
|
+
|
34
|
+
## [1.0.0-beta.4] - 2025-01-16
|
35
|
+
|
36
|
+
### Fixed
|
37
|
+
|
38
|
+
- **Code Cleanup**: Removed deprecated methods from JwtValidator
|
39
|
+
- Removed old validate_token_* methods to reduce API surface
|
40
|
+
- Enhanced validate_enriched documentation with parameter examples
|
41
|
+
- Maintained backward compatibility for main validation methods
|
42
|
+
|
10
43
|
## [1.0.0-beta.3] - 2025-01-16
|
11
44
|
|
12
45
|
### Fixed
|
@@ -43,7 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
43
76
|
- Extracción inteligente de detalles de error
|
44
77
|
- Códigos de error estandarizados
|
45
78
|
|
46
|
-
- **Validación Enriquecida**: Nuevo método `
|
79
|
+
- **Validación Enriquecida**: Nuevo método `validate_enriched`
|
47
80
|
- Validación de tokens con datos contextuales del usuario
|
48
81
|
- Recuperación automática de permisos, organizaciones y aplicaciones
|
49
82
|
- Degradación elegante si la recuperación de datos falla
|
data/CLAUDE.md
CHANGED
@@ -37,22 +37,16 @@ gem build jwt_auth_cognito.gemspec
|
|
37
37
|
bundle exec rake install
|
38
38
|
|
39
39
|
# Test gem packaging
|
40
|
-
gem contents jwt_auth_cognito-0.
|
41
|
-
|
42
|
-
# Version management (
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
rake release:stable # Stable release (requires confirmation)
|
51
|
-
|
52
|
-
# Direct publishing
|
53
|
-
rake publish:beta # Build and publish beta version
|
54
|
-
rake publish:rc # Build and publish RC version
|
55
|
-
rake publish:stable # Build and publish stable (requires confirmation)
|
40
|
+
gem contents jwt_auth_cognito-1.0.0-beta.4.gem
|
41
|
+
|
42
|
+
# Version management (Manual in version.rb file)
|
43
|
+
# Edit lib/jwt_auth_cognito/version.rb to update VERSION constant
|
44
|
+
# Example: VERSION = '1.0.0-beta.5'
|
45
|
+
|
46
|
+
# The CI/CD pipeline handles automatic deployment:
|
47
|
+
# - Beta releases: Automatic deployment when pushed to develop branch
|
48
|
+
# - RC releases: Automatic deployment when tagged with v*-rc.*
|
49
|
+
# - Stable releases: Manual deployment when tagged with v[0-9]*.*
|
56
50
|
```
|
57
51
|
|
58
52
|
### Configuration Generation
|
@@ -70,18 +64,19 @@ rake jwt_auth_cognito:test_cognito # Test Cognito connection
|
|
70
64
|
## Architecture Overview
|
71
65
|
|
72
66
|
### Core Components
|
73
|
-
- **JwtValidator**: Main validation orchestrator that coordinates JWKS validation, blacklist checking,
|
67
|
+
- **JwtValidator**: Main validation orchestrator that coordinates JWKS validation, blacklist checking, user data retrieval, and API key validation
|
74
68
|
- **JwksService**: Handles AWS Cognito JWKS fetching, caching, and signature validation
|
75
69
|
- **RedisService**: Low-level Redis operations with comprehensive TLS support and retry logic
|
76
70
|
- **TokenBlacklistService**: High-level token revocation and blacklist management
|
77
71
|
- **UserDataService**: User data retrieval from Redis with caching and auth-service compatibility
|
72
|
+
- **ApiKeyValidator**: API key validation with system and app-level access control
|
78
73
|
- **ErrorUtils**: Centralized error handling and categorization system
|
79
74
|
- **SSMService**: AWS Parameter Store integration for secure certificate management (auth-service compatible)
|
80
75
|
- **Configuration**: Centralized configuration with environment variable fallbacks
|
81
76
|
|
82
77
|
### Key Design Patterns
|
83
78
|
|
84
|
-
**Service Layer Architecture**: Each major functionality (JWT validation, JWKS handling, Redis operations, blacklisting, user data retrieval) is isolated into dedicated service classes that can be used independently or orchestrated through JwtValidator.
|
79
|
+
**Service Layer Architecture**: Each major functionality (JWT validation, JWKS handling, Redis operations, blacklisting, user data retrieval, API key validation) is isolated into dedicated service classes that can be used independently or orchestrated through JwtValidator.
|
85
80
|
|
86
81
|
**Configuration Management**: Dual configuration approach supporting both programmatic configuration and environment variables, with automatic fallback chain for maximum flexibility.
|
87
82
|
|
@@ -97,6 +92,7 @@ rake jwt_auth_cognito:test_cognito # Test Cognito connection
|
|
97
92
|
- **Retry Logic**: Exponential backoff for failed operations
|
98
93
|
- **Blacklist Strategy**: Uses Redis sets with automatic TTL management for token revocation
|
99
94
|
- **User Token Tracking**: Maintains user-to-tokens mapping for bulk revocation capabilities
|
95
|
+
- **Generic Operations**: Provides `get()` and `set()` methods for API key storage and general Redis operations with TTL support
|
100
96
|
|
101
97
|
### ✅ **SSM Parameter Store Integration** - NEW December 2024
|
102
98
|
|
@@ -109,9 +105,9 @@ rake jwt_auth_cognito:test_cognito # Test Cognito connection
|
|
109
105
|
# 3. Environment variable
|
110
106
|
|
111
107
|
# SSM configuration (matching auth-service pattern)
|
112
|
-
config.
|
113
|
-
config.
|
114
|
-
# Results in SSM parameter: /
|
108
|
+
config.redis_ca_cert_path = "redis" # SSM path segment
|
109
|
+
config.redis_ca_cert_name = "ca-cert" # Certificate name
|
110
|
+
# Results in SSM parameter: /redis/ca-cert
|
115
111
|
|
116
112
|
# Automatic fallback to file system
|
117
113
|
config.redis_ca_cert_path = "/path/to/certs"
|
@@ -175,18 +171,30 @@ validator = JwtAuthCognito.create_cognito_validator(
|
|
175
171
|
ca_cert_name: ENV['REDIS_CA_CERT_NAME'],
|
176
172
|
verify_mode: ENV['REDIS_VERIFY_MODE'] || 'peer'
|
177
173
|
},
|
178
|
-
|
174
|
+
enable_api_key_validation: true, # Enable API key validation
|
175
|
+
enable_user_data_retrieval: true # Enable user data enrichment
|
179
176
|
)
|
180
177
|
|
181
178
|
# Initialize Redis connection and services
|
182
179
|
validator.initialize!
|
183
180
|
|
184
181
|
# 🌟 Main validation method with complete functionality
|
185
|
-
result = validator.
|
182
|
+
result = validator.validate_enriched(token)
|
183
|
+
|
184
|
+
# Advanced usage with options
|
185
|
+
result = validator.validate_enriched(
|
186
|
+
token,
|
187
|
+
api_key, # Optional API key
|
188
|
+
{
|
189
|
+
force_secure: true, # Force JWKS validation
|
190
|
+
require_app_access: true # Verify app access
|
191
|
+
}
|
192
|
+
)
|
186
193
|
|
187
194
|
if result[:valid]
|
188
195
|
puts "✅ Valid token:"
|
189
196
|
puts "User: #{result[:sub]}"
|
197
|
+
puts "API Key: #{result[:api_key][:name]}" if result[:api_key]
|
190
198
|
puts "Permissions: #{result[:user_permissions]}"
|
191
199
|
puts "Organizations: #{result[:user_organizations]}"
|
192
200
|
puts "Applications: #{result[:applications]}"
|
@@ -221,9 +229,9 @@ REDIS_READ_TIMEOUT=10
|
|
221
229
|
|
222
230
|
### TLS/SSL Certificate Configuration
|
223
231
|
```bash
|
224
|
-
# AWS SSM Parameter Store (
|
225
|
-
|
226
|
-
|
232
|
+
# AWS SSM Parameter Store (auth-service compatibility)
|
233
|
+
REDIS_CA_CERT_PATH=redis # SSM path segment
|
234
|
+
REDIS_CA_CERT_NAME=ca-cert # SSM parameter name
|
227
235
|
|
228
236
|
# Local file system fallback
|
229
237
|
REDIS_CA_CERT_PATH=/path/to/certs
|
@@ -234,27 +242,32 @@ REDIS_CA_CERT="-----BEGIN CERTIFICATE-----..."
|
|
234
242
|
|
235
243
|
# TLS settings
|
236
244
|
REDIS_VERIFY_MODE=peer # 'peer' or 'none'
|
237
|
-
REDIS_TLS_MIN_VERSION=
|
238
|
-
REDIS_TLS_MAX_VERSION=
|
245
|
+
REDIS_TLS_MIN_VERSION=TLSv1_2
|
246
|
+
REDIS_TLS_MAX_VERSION=TLSv1_3
|
239
247
|
```
|
240
248
|
|
241
249
|
### AWS Configuration (for SSM)
|
242
250
|
```bash
|
243
251
|
AWS_REGION=us-east-1
|
244
|
-
AWS_ACCESS_KEY_ID=your-access-key
|
245
|
-
AWS_SECRET_ACCESS_KEY=your-secret-key
|
246
|
-
#
|
252
|
+
AWS_ACCESS_KEY_ID=your-access-key # Opcional, usa aws configure si no se proporciona
|
253
|
+
AWS_SECRET_ACCESS_KEY=your-secret-key # Opcional, usa aws configure si no se proporciona
|
254
|
+
AWS_SESSION_TOKEN=your-session-token # Opcional, para credenciales temporales
|
255
|
+
AWS_SSM_ENDPOINT=https://ssm.us-east-1.amazonaws.com # Opcional, para VPC endpoints
|
256
|
+
# Or use IAM roles/instance profiles (recommended for production)
|
247
257
|
```
|
248
258
|
|
249
|
-
###
|
259
|
+
### Feature Configuration
|
250
260
|
```bash
|
261
|
+
# API Key validation settings
|
262
|
+
ENABLE_API_KEY_VALIDATION=true # Enable API key validation functionality
|
263
|
+
|
251
264
|
# User data retrieval settings
|
252
|
-
ENABLE_USER_DATA_RETRIEVAL=true
|
265
|
+
ENABLE_USER_DATA_RETRIEVAL=true # Enable user data enrichment functionality
|
253
266
|
INCLUDE_APPLICATIONS=true
|
254
267
|
INCLUDE_ORGANIZATIONS=true
|
255
268
|
INCLUDE_ROLES=true
|
256
269
|
INCLUDE_EFFECTIVE_PERMISSIONS=false
|
257
|
-
USER_DATA_CACHE_TIMEOUT=300
|
270
|
+
USER_DATA_CACHE_TIMEOUT=300 # 5 minutes
|
258
271
|
```
|
259
272
|
|
260
273
|
### Caching and Performance
|
@@ -291,14 +304,16 @@ JWKS_CACHE_TTL=3600 # 1 hour
|
|
291
304
|
|
292
305
|
## Version Compatibility
|
293
306
|
|
294
|
-
### ✅ **Updated January 2025 - Version 0.
|
307
|
+
### ✅ **Updated January 2025 - Version 1.0.0-beta.5**
|
295
308
|
|
296
|
-
**
|
309
|
+
**Production-ready beta with deployment automation and API key support**
|
297
310
|
|
298
311
|
- ✅ UserDataService with auth-service compatibility
|
299
312
|
- ✅ Enhanced error handling with ErrorUtils
|
300
313
|
- ✅ Enriched token validation with user context
|
301
|
-
- ✅ Automated CI/CD pipeline with Bitbucket
|
314
|
+
- ✅ Automated CI/CD pipeline with Bitbucket (deployment issues resolved)
|
315
|
+
- ✅ Complete API key validation support with Redis storage
|
316
|
+
- ✅ Generic Redis operations (`get`/`set`) for extensibility
|
302
317
|
- ✅ Synchronized feature set with Node.js package (maintaining independent versioning)
|
303
318
|
- ✅ Maintains consistent API across language implementations
|
304
319
|
|
@@ -315,31 +330,46 @@ The gem uses Bitbucket Pipelines for automated deployment to RubyGems.org:
|
|
315
330
|
|
316
331
|
#### Pipeline Configuration
|
317
332
|
- **Beta releases** (`v*-beta.*`): Automatic deployment
|
318
|
-
- **RC releases** (`v*-rc.*`): Automatic deployment
|
333
|
+
- **RC releases** (`v*-rc.*`): Automatic deployment
|
319
334
|
- **Stable releases** (`v[0-9]*.*`): Manual deployment with confirmation
|
320
335
|
- **Testing**: Automated on all branches with comprehensive test suite
|
321
336
|
|
337
|
+
#### RubyGems Credentials Setup
|
338
|
+
The pipeline uses environment variable `RUBYGEMS_API_KEY` with correct YAML format:
|
339
|
+
```bash
|
340
|
+
# Pipeline creates credentials file with correct format:
|
341
|
+
printf ':rubygems_api_key: %s\n' "$RUBYGEMS_API_KEY" > ~/.gem/credentials
|
342
|
+
# Note: The colon prefix is required for valid YAML format
|
343
|
+
# Using printf to avoid YAML parsing issues with echo and colons
|
344
|
+
```
|
345
|
+
|
322
346
|
#### Deployment Commands
|
323
347
|
|
324
|
-
####
|
348
|
+
#### Version Management Process
|
349
|
+
|
350
|
+
**1. Update Version Number**
|
325
351
|
```bash
|
326
|
-
#
|
327
|
-
|
328
|
-
|
329
|
-
git push origin develop
|
330
|
-
# → Pipeline automatically creates and publishes beta version
|
352
|
+
# Edit the version file manually
|
353
|
+
vim lib/jwt_auth_cognito/version.rb
|
354
|
+
# Update VERSION constant: VERSION = '1.0.0-beta.5'
|
331
355
|
```
|
332
356
|
|
333
|
-
|
357
|
+
**2. Automatic Beta Deployment**
|
334
358
|
```bash
|
335
|
-
#
|
336
|
-
git
|
359
|
+
# Push to develop branch - automatic beta deployment
|
360
|
+
git add lib/jwt_auth_cognito/version.rb
|
361
|
+
git commit -m "bump: version 1.0.0-beta.5"
|
362
|
+
git push origin develop
|
363
|
+
# → Pipeline automatically publishes beta version to RubyGems
|
364
|
+
```
|
337
365
|
|
366
|
+
**3. Manual Tag Deployment (Alternative)**
|
367
|
+
```bash
|
338
368
|
# RC release
|
339
|
-
git tag
|
369
|
+
git tag v1.0.0-rc.1 && git push origin v1.0.0-rc.1
|
340
370
|
|
341
371
|
# Stable release
|
342
|
-
git tag
|
372
|
+
git tag v1.0.0 && git push origin v1.0.0
|
343
373
|
```
|
344
374
|
|
345
375
|
#### Helper Scripts
|
data/README.md
CHANGED
@@ -49,10 +49,10 @@ JwtAuthCognito.configure do |config|
|
|
49
49
|
config.redis_password = 'tu-password-redis' # Opcional
|
50
50
|
config.redis_db = 0
|
51
51
|
|
52
|
-
# Configuración TLS para Redis (Producción)
|
52
|
+
# Configuración TLS para Redis (Producción - compatible con auth-service)
|
53
53
|
config.redis_ssl = true
|
54
|
-
config.redis_ca_cert_path = '
|
55
|
-
config.redis_ca_cert_name = '
|
54
|
+
config.redis_ca_cert_path = 'redis' # AWS SSM path
|
55
|
+
config.redis_ca_cert_name = 'ca-cert' # AWS SSM parameter name
|
56
56
|
config.redis_tls_min_version = 'TLSv1.2'
|
57
57
|
config.redis_tls_max_version = 'TLSv1.3'
|
58
58
|
config.redis_verify_mode = 'peer'
|
@@ -60,6 +60,10 @@ JwtAuthCognito.configure do |config|
|
|
60
60
|
# Opcional: Configuraciones de cache y validación
|
61
61
|
config.jwks_cache_ttl = 3600 # 1 hora
|
62
62
|
config.validation_mode = :secure # :secure o :basic
|
63
|
+
|
64
|
+
# Opcional: Habilitar funcionalidades específicas
|
65
|
+
config.enable_api_key_validation = true # Validación de API keys
|
66
|
+
config.enable_user_data_retrieval = true # Enriquecimiento de datos de usuario
|
63
67
|
end
|
64
68
|
```
|
65
69
|
|
@@ -81,15 +85,95 @@ REDIS_PASSWORD=tu-password
|
|
81
85
|
REDIS_DB=0
|
82
86
|
REDIS_TLS=true
|
83
87
|
|
84
|
-
# Configuración TLS de Redis
|
85
|
-
REDIS_CA_CERT_PATH
|
86
|
-
REDIS_CA_CERT_NAME=
|
87
|
-
REDIS_TLS_MIN_VERSION=
|
88
|
-
REDIS_TLS_MAX_VERSION=
|
88
|
+
# Configuración TLS de Redis (compatible con auth-service)
|
89
|
+
REDIS_CA_CERT_PATH=redis # Para AWS SSM (path del parámetro)
|
90
|
+
REDIS_CA_CERT_NAME=ca-cert # Para AWS SSM (nombre del parámetro)
|
91
|
+
REDIS_TLS_MIN_VERSION=TLSv1_2
|
92
|
+
REDIS_TLS_MAX_VERSION=TLSv1_3
|
89
93
|
REDIS_VERIFY_MODE=peer
|
90
94
|
|
91
95
|
# Configuración de cache
|
92
96
|
JWKS_CACHE_TTL=3600
|
97
|
+
|
98
|
+
# Configuración AWS para Parameter Store (SSM)
|
99
|
+
# Nota: Si no se configuran, usa la cadena de credenciales estándar de AWS (aws configure, IAM roles, etc.)
|
100
|
+
AWS_REGION=us-east-1
|
101
|
+
AWS_ACCESS_KEY_ID=your-access-key # Opcional, usa aws configure si no se proporciona
|
102
|
+
AWS_SECRET_ACCESS_KEY=your-secret-key # Opcional, usa aws configure si no se proporciona
|
103
|
+
AWS_SESSION_TOKEN=your-session-token # Opcional, para credenciales temporales
|
104
|
+
AWS_SSM_ENDPOINT=https://ssm.us-east-1.amazonaws.com # Opcional, para VPC endpoints
|
105
|
+
|
106
|
+
# Habilitar funcionalidades específicas
|
107
|
+
ENABLE_API_KEY_VALIDATION=true # Validación de API keys
|
108
|
+
ENABLE_USER_DATA_RETRIEVAL=true # Enriquecimiento de datos de usuario
|
109
|
+
```
|
110
|
+
|
111
|
+
### Opciones de Configuración Boolean
|
112
|
+
|
113
|
+
La gema soporta las siguientes opciones boolean para habilitar funcionalidades específicas:
|
114
|
+
|
115
|
+
- **`enable_api_key_validation`** - Habilita la validación de API keys para control de acceso a nivel de sistema y aplicación (default: false)
|
116
|
+
- **`enable_user_data_retrieval`** - Habilita el enriquecimiento de datos de usuario con permisos, organizaciones y aplicaciones (default: false)
|
117
|
+
|
118
|
+
Estas opciones permiten control granular sobre qué características están activas, optimizando el rendimiento habilitando solo la funcionalidad necesaria.
|
119
|
+
|
120
|
+
## Configuración AWS para Development
|
121
|
+
|
122
|
+
### Desarrollo Local
|
123
|
+
|
124
|
+
Para desarrollo local, la gema usa la **cadena de credenciales estándar de AWS**:
|
125
|
+
|
126
|
+
```bash
|
127
|
+
# Opción 1: Configurar perfil por defecto (recomendado para desarrollo)
|
128
|
+
aws configure
|
129
|
+
# Configura: access key, secret key, región, formato
|
130
|
+
|
131
|
+
# Opción 2: Usar perfil específico
|
132
|
+
aws configure --profile mi-proyecto
|
133
|
+
export AWS_PROFILE=mi-proyecto
|
134
|
+
|
135
|
+
# Opción 3: Variables de entorno específicas del proyecto
|
136
|
+
export AWS_REGION=us-east-1
|
137
|
+
export AWS_ACCESS_KEY_ID=AKIA...
|
138
|
+
export AWS_SECRET_ACCESS_KEY=xyz123...
|
139
|
+
```
|
140
|
+
|
141
|
+
### Orden de Prioridad de Credenciales
|
142
|
+
|
143
|
+
1. **Variables de entorno** (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`)
|
144
|
+
2. **Archivo de credenciales** (`~/.aws/credentials`)
|
145
|
+
3. **Perfil AWS** (`AWS_PROFILE` o `[default]`)
|
146
|
+
4. **IAM roles** (en EC2, ECS, Lambda, etc.)
|
147
|
+
|
148
|
+
### Permisos Necesarios para SSM
|
149
|
+
|
150
|
+
Tu usuario/rol AWS necesita permisos para acceder a Parameter Store:
|
151
|
+
|
152
|
+
```json
|
153
|
+
{
|
154
|
+
"Version": "2012-10-17",
|
155
|
+
"Statement": [
|
156
|
+
{
|
157
|
+
"Effect": "Allow",
|
158
|
+
"Action": [
|
159
|
+
"ssm:GetParameter",
|
160
|
+
"ssm:GetParameters"
|
161
|
+
],
|
162
|
+
"Resource": "arn:aws:ssm:us-east-1:*:parameter/redis/*"
|
163
|
+
}
|
164
|
+
]
|
165
|
+
}
|
166
|
+
```
|
167
|
+
|
168
|
+
### Debugging de Configuración AWS
|
169
|
+
|
170
|
+
La gema incluye logging detallado para diagnosis:
|
171
|
+
|
172
|
+
```
|
173
|
+
📡 Getting certificate from Parameter Store: /redis/ca-cert
|
174
|
+
🌍 AWS Region: us-east-1
|
175
|
+
🔑 Credentials configured: No (using IAM role/profile) 👈 Indica uso de aws configure
|
176
|
+
✅ Certificate obtained from SSM and cached
|
93
177
|
```
|
94
178
|
|
95
179
|
## Uso
|
@@ -135,7 +219,7 @@ validator = JwtAuthCognito::JwtValidator.new
|
|
135
219
|
validator.initialize! # Inicializar servicios
|
136
220
|
|
137
221
|
# Validación enriquecida con datos de usuario desde Redis
|
138
|
-
result = validator.
|
222
|
+
result = validator.validate_enriched(jwt_token)
|
139
223
|
|
140
224
|
if result[:valid]
|
141
225
|
puts "Token válido!"
|
@@ -159,6 +243,109 @@ if result[:valid]
|
|
159
243
|
end
|
160
244
|
```
|
161
245
|
|
246
|
+
#### Opciones Avanzadas para validate_enriched
|
247
|
+
|
248
|
+
El método `validate_enriched` acepta múltiples parámetros para casos de uso específicos:
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
# Sintaxis completa
|
252
|
+
result = validator.validate_enriched(token, api_key, options)
|
253
|
+
|
254
|
+
# 1. Solo token (caso más simple)
|
255
|
+
result = validator.validate_enriched(jwt_token)
|
256
|
+
|
257
|
+
# 2. Con API key
|
258
|
+
result = validator.validate_enriched(jwt_token, api_key)
|
259
|
+
|
260
|
+
# 3. Con opciones adicionales
|
261
|
+
result = validator.validate_enriched(jwt_token, nil, {
|
262
|
+
force_secure: true, # Forzar validación segura (JWKS)
|
263
|
+
require_app_access: true # Requerir acceso a aplicación específica
|
264
|
+
})
|
265
|
+
|
266
|
+
# 4. Con API key y opciones
|
267
|
+
result = validator.validate_enriched(jwt_token, api_key, {
|
268
|
+
force_secure: true,
|
269
|
+
require_app_access: true
|
270
|
+
})
|
271
|
+
|
272
|
+
# 5. Solo con opciones (sin API key)
|
273
|
+
result = validator.validate_enriched(jwt_token, nil, {
|
274
|
+
force_secure: false, # Usar modo básico de validación
|
275
|
+
require_app_access: false # No verificar acceso a aplicación
|
276
|
+
})
|
277
|
+
```
|
278
|
+
|
279
|
+
**Parámetros disponibles:**
|
280
|
+
|
281
|
+
- **`token`** (String): JWT token a validar
|
282
|
+
- **`api_key`** (String, opcional): API key para validación adicional
|
283
|
+
- **`options`** (Hash, opcional):
|
284
|
+
- `force_secure`: Forzar validación JWKS incluso en desarrollo
|
285
|
+
- `require_app_access`: Verificar que el usuario tenga acceso a la aplicación del API key
|
286
|
+
|
287
|
+
```ruby
|
288
|
+
# Ejemplo con todas las opciones
|
289
|
+
result = validator.validate_enriched(
|
290
|
+
jwt_token,
|
291
|
+
'api-key-64-hex-characters',
|
292
|
+
{
|
293
|
+
force_secure: true,
|
294
|
+
require_app_access: true
|
295
|
+
}
|
296
|
+
)
|
297
|
+
|
298
|
+
if result[:valid]
|
299
|
+
puts "✅ Validación completa exitosa"
|
300
|
+
puts "Usuario: #{result[:sub]}"
|
301
|
+
puts "API Key: #{result[:api_key][:name]}"
|
302
|
+
puts "Permisos: #{result[:user_permissions]}"
|
303
|
+
puts "Apps disponibles: #{result[:applications]&.map { |app| app['appId'] }}"
|
304
|
+
else
|
305
|
+
puts "❌ Error: #{result[:error]}"
|
306
|
+
end
|
307
|
+
```
|
308
|
+
|
309
|
+
### Validación con API Keys
|
310
|
+
|
311
|
+
Para usar validación de API keys, habilita la funcionalidad en la configuración:
|
312
|
+
|
313
|
+
```ruby
|
314
|
+
# Configurar con validación de API keys habilitada
|
315
|
+
JwtAuthCognito.configure do |config|
|
316
|
+
# ... configuración básica ...
|
317
|
+
config.enable_api_key_validation = true
|
318
|
+
end
|
319
|
+
|
320
|
+
validator = JwtAuthCognito::JwtValidator.new
|
321
|
+
validator.initialize!
|
322
|
+
|
323
|
+
# Validar token con API key opcional
|
324
|
+
api_key = 'api-key-64-hex-characters-1234567890abcdef1234567890abcdef12345678'
|
325
|
+
result = validator.validate(jwt_token, api_key: api_key)
|
326
|
+
|
327
|
+
if result[:valid]
|
328
|
+
puts "✅ Token y API key válidos"
|
329
|
+
puts "Usuario: #{result[:sub]}"
|
330
|
+
|
331
|
+
# Información del API key
|
332
|
+
if result[:api_key_data]
|
333
|
+
key_data = result[:api_key_data]
|
334
|
+
puts "API Key: #{key_data[:name]}"
|
335
|
+
puts "Scope: #{key_data[:scope]}"
|
336
|
+
puts "Permisos: #{key_data[:permissions].join(', ')}"
|
337
|
+
puts "App ID: #{key_data[:app_id]}" if key_data[:app_id]
|
338
|
+
end
|
339
|
+
else
|
340
|
+
puts "❌ Error: #{result[:error]}"
|
341
|
+
end
|
342
|
+
```
|
343
|
+
|
344
|
+
**Tipos de API Keys soportados:**
|
345
|
+
- **System API Keys** (`scope: 'system'`) - Acceso transversal a todas las aplicaciones
|
346
|
+
- **App API Keys** (`scope: 'app'`) - Acceso restringido a una aplicación específica
|
347
|
+
- **Client API Keys** (`scope: 'client'`) - Para aplicaciones cliente
|
348
|
+
|
162
349
|
### Factory Method para Configuración Simplificada (Nuevo v0.3.0)
|
163
350
|
|
164
351
|
```ruby
|
@@ -179,14 +366,15 @@ validator = JwtAuthCognito.create_cognito_validator(
|
|
179
366
|
ca_cert_path: ENV['REDIS_CA_CERT_PATH'],
|
180
367
|
ca_cert_name: ENV['REDIS_CA_CERT_NAME']
|
181
368
|
},
|
182
|
-
|
369
|
+
enable_api_key_validation: true, # Habilitar validación de API keys
|
370
|
+
enable_user_data_retrieval: true # Habilitar enriquecimiento de datos
|
183
371
|
)
|
184
372
|
|
185
373
|
# Inicializar conexiones (incluye Redis)
|
186
374
|
validator.initialize!
|
187
375
|
|
188
376
|
# Usar inmediatamente con validación enriquecida
|
189
|
-
result = validator.
|
377
|
+
result = validator.validate_enriched(token)
|
190
378
|
|
191
379
|
if result[:valid]
|
192
380
|
puts "✅ Token válido con datos enriquecidos:"
|
data/bitbucket-pipelines.yml
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
# Bitbucket Pipeline para jwt_auth_cognito Ruby Gem
|
1
|
+
# Bitbucket Pipeline para jwt_auth_cognito Ruby Gem
|
2
2
|
# Configuración CI/CD para RubyGems con Git Flow
|
3
|
+
#
|
4
|
+
# COMPORTAMIENTO:
|
5
|
+
# - Push a develop: Publica version definida en codigo sin crear tags
|
6
|
+
# - Tags creados por Git Flow: Activan pipelines específicos según tipo de version
|
7
|
+
# - No hay duplicación de deploys (develop no crea tags automáticos)
|
3
8
|
|
4
9
|
image: ruby:3.1
|
5
10
|
|
@@ -41,20 +46,17 @@ pipelines:
|
|
41
46
|
- bundle exec rspec
|
42
47
|
- echo "Ejecutando linting..."
|
43
48
|
- bundle exec rubocop
|
44
|
-
- echo "
|
45
|
-
- bundle exec rake version:beta
|
49
|
+
- echo "Usando version definida en codigo..."
|
46
50
|
- echo "Building gem..."
|
47
51
|
- gem build jwt_auth_cognito.gemspec
|
48
52
|
- echo "Configurando credenciales RubyGems..."
|
49
53
|
- mkdir -p ~/.gem
|
50
|
-
- '
|
54
|
+
- "printf ':rubygems_api_key: %s\\n' \"$RUBYGEMS_API_KEY\" > ~/.gem/credentials"
|
51
55
|
- chmod 0600 ~/.gem/credentials
|
52
56
|
- echo "Publicando version beta a RubyGems..."
|
53
57
|
- gem push *.gem
|
54
|
-
- echo "
|
55
|
-
-
|
56
|
-
- git config user.email "pipeline@bitbucket.org"
|
57
|
-
- NEW_VERSION=$(ruby -r './lib/jwt_auth_cognito/version' -e 'puts JwtAuthCognito::VERSION') && git tag "v$NEW_VERSION" && git push origin "v$NEW_VERSION" && echo "Beta v$NEW_VERSION publicada automaticamente"
|
58
|
+
- echo "Deploy de develop completado - Version beta publicada sin tag automatico"
|
59
|
+
- echo "Los tags se crearan automaticamente en releases usando Git Flow"
|
58
60
|
|
59
61
|
main:
|
60
62
|
- step:
|
@@ -93,7 +95,7 @@ pipelines:
|
|
93
95
|
- gem build jwt_auth_cognito.gemspec
|
94
96
|
- echo "Configurando credenciales RubyGems..."
|
95
97
|
- mkdir -p ~/.gem
|
96
|
-
- '
|
98
|
+
- "printf ':rubygems_api_key: %s\\n' \"$RUBYGEMS_API_KEY\" > ~/.gem/credentials"
|
97
99
|
- chmod 0600 ~/.gem/credentials
|
98
100
|
- echo "Publicando a RubyGems con tag beta..."
|
99
101
|
- gem push *.gem
|
@@ -116,7 +118,7 @@ pipelines:
|
|
116
118
|
- gem build jwt_auth_cognito.gemspec
|
117
119
|
- echo "Configurando credenciales RubyGems..."
|
118
120
|
- mkdir -p ~/.gem
|
119
|
-
- '
|
121
|
+
- "printf ':rubygems_api_key: %s\\n' \"$RUBYGEMS_API_KEY\" > ~/.gem/credentials"
|
120
122
|
- chmod 0600 ~/.gem/credentials
|
121
123
|
- echo "Publicando a RubyGems..."
|
122
124
|
- gem push *.gem
|
@@ -151,7 +153,7 @@ pipelines:
|
|
151
153
|
- echo "🚨 DEPLOY DE PRODUCCIÓN - Versión estable"
|
152
154
|
- echo "Configurando credenciales RubyGems..."
|
153
155
|
- mkdir -p ~/.gem
|
154
|
-
- '
|
156
|
+
- "printf ':rubygems_api_key: %s\\n' \"$RUBYGEMS_API_KEY\" > ~/.gem/credentials"
|
155
157
|
- chmod 0600 ~/.gem/credentials
|
156
158
|
- echo "Publicando version ESTABLE a RubyGems..."
|
157
159
|
- gem push *.gem
|
@@ -193,7 +195,7 @@ pipelines:
|
|
193
195
|
- gem build jwt_auth_cognito.gemspec
|
194
196
|
- echo "Configurando credenciales RubyGems..."
|
195
197
|
- mkdir -p ~/.gem
|
196
|
-
- '
|
198
|
+
- "printf ':rubygems_api_key: %s\\n' \"$RUBYGEMS_API_KEY\" > ~/.gem/credentials"
|
197
199
|
- chmod 0600 ~/.gem/credentials
|
198
200
|
- echo "📤 Desplegando a RubyGems..."
|
199
201
|
- gem push *.gem
|
@@ -216,7 +218,7 @@ pipelines:
|
|
216
218
|
- gem build jwt_auth_cognito.gemspec
|
217
219
|
- echo "Configurando credenciales RubyGems..."
|
218
220
|
- mkdir -p ~/.gem
|
219
|
-
- '
|
221
|
+
- "printf ':rubygems_api_key: %s\\n' \"$RUBYGEMS_API_KEY\" > ~/.gem/credentials"
|
220
222
|
- chmod 0600 ~/.gem/credentials
|
221
223
|
- echo "📤 Desplegando a RubyGems..."
|
222
224
|
- gem push *.gem
|
@@ -244,7 +246,7 @@ pipelines:
|
|
244
246
|
- gem build jwt_auth_cognito.gemspec
|
245
247
|
- echo "Configurando credenciales RubyGems..."
|
246
248
|
- mkdir -p ~/.gem
|
247
|
-
- '
|
249
|
+
- "printf ':rubygems_api_key: %s\\n' \"$RUBYGEMS_API_KEY\" > ~/.gem/credentials"
|
248
250
|
- chmod 0600 ~/.gem/credentials
|
249
251
|
- echo "📤 Desplegando versión ESTABLE a RubyGems..."
|
250
252
|
- gem push *.gem
|
@@ -270,4 +272,4 @@ pipelines:
|
|
270
272
|
# Configuración de caches
|
271
273
|
definitions:
|
272
274
|
caches:
|
273
|
-
bundler: vendor/bundle
|
275
|
+
bundler: vendor/bundle
|
data/jwt_auth_cognito.gemspec
CHANGED
@@ -45,7 +45,6 @@ Gem::Specification.new do |spec|
|
|
45
45
|
spec.add_dependency 'aws-sdk-ssm', '~> 1.0' # For AWS Parameter Store support
|
46
46
|
spec.add_dependency 'json', '~> 2.0'
|
47
47
|
spec.add_dependency 'jwt', '~> 2.0'
|
48
|
-
spec.add_dependency 'openssl', '>= 2.1.0' # For TLS support
|
49
48
|
spec.add_dependency 'redis', '>= 4.2.5', '< 6.0' # Compatible with llegando-neo redis version
|
50
49
|
|
51
50
|
# Development dependencies
|
@@ -55,5 +54,4 @@ Gem::Specification.new do |spec|
|
|
55
54
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
56
55
|
spec.add_development_dependency 'rubocop', '~> 1.0'
|
57
56
|
spec.add_development_dependency 'webmock', '~> 3.0'
|
58
|
-
spec.metadata['rubygems_mfa_required'] = 'true'
|
59
57
|
end
|
@@ -7,7 +7,6 @@ module JwtAuthCognito
|
|
7
7
|
:redis_ssl, :redis_timeout, :redis_connect_timeout, :redis_read_timeout,
|
8
8
|
:redis_ca_cert_path, :redis_ca_cert_name, :redis_verify_mode,
|
9
9
|
:redis_tls_min_version, :redis_tls_max_version,
|
10
|
-
:redis_ca_cert_ssm_path, :redis_ca_cert_ssm_name,
|
11
10
|
:jwks_cache_ttl, :validation_mode, :environment,
|
12
11
|
:enable_api_key_validation, :enable_user_data_retrieval
|
13
12
|
|
@@ -27,14 +26,12 @@ module JwtAuthCognito
|
|
27
26
|
@redis_connect_timeout = (ENV['REDIS_CONNECT_TIMEOUT'] || 10).to_i
|
28
27
|
@redis_read_timeout = (ENV['REDIS_READ_TIMEOUT'] || 10).to_i
|
29
28
|
|
30
|
-
# TLS specific configuration
|
29
|
+
# TLS specific configuration (compatible with auth-service)
|
31
30
|
@redis_ca_cert_path = ENV.fetch('REDIS_CA_CERT_PATH', nil)
|
32
31
|
@redis_ca_cert_name = ENV.fetch('REDIS_CA_CERT_NAME', nil)
|
33
|
-
@redis_ca_cert_ssm_path = ENV.fetch('REDIS_CA_CERT_SSM_PATH', nil)
|
34
|
-
@redis_ca_cert_ssm_name = ENV.fetch('REDIS_CA_CERT_SSM_NAME', nil)
|
35
32
|
@redis_verify_mode = ENV['REDIS_VERIFY_MODE'] || 'peer'
|
36
|
-
@redis_tls_min_version = ENV['REDIS_TLS_MIN_VERSION'] || '
|
37
|
-
@redis_tls_max_version = ENV['REDIS_TLS_MAX_VERSION'] || '
|
33
|
+
@redis_tls_min_version = ENV['REDIS_TLS_MIN_VERSION'] || 'TLSv1_2'
|
34
|
+
@redis_tls_max_version = ENV['REDIS_TLS_MAX_VERSION'] || 'TLSv1_3'
|
38
35
|
|
39
36
|
@jwks_cache_ttl = (ENV['JWKS_CACHE_TTL'] || 3600).to_i # 1 hour
|
40
37
|
@environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['NODE_ENV'] || 'development'
|
@@ -131,85 +131,6 @@ module JwtAuthCognito
|
|
131
131
|
validate(token, options.merge(api_key: api_key, enrich_user_data: true))
|
132
132
|
end
|
133
133
|
|
134
|
-
# ========== LEGACY METHODS (DEPRECATED) ==========
|
135
|
-
|
136
|
-
# @deprecated Use validate() or validate_with_api_key() instead
|
137
|
-
def validate_token_with_api_key(token, api_key = nil, options = {})
|
138
|
-
puts 'WARNING: validate_token_with_api_key is deprecated. Use validate() or validate_with_api_key() instead.'
|
139
|
-
result = validate(token, options.merge(api_key: api_key, enrich_user_data: false))
|
140
|
-
{
|
141
|
-
valid: result[:valid],
|
142
|
-
payload: result[:payload],
|
143
|
-
sub: result[:sub],
|
144
|
-
username: result[:username],
|
145
|
-
token_use: result[:token_use],
|
146
|
-
api_key: result[:api_key],
|
147
|
-
error: result[:error]
|
148
|
-
}
|
149
|
-
end
|
150
|
-
|
151
|
-
# @deprecated Use validate_with_app_access() instead
|
152
|
-
def validate_token_with_app_id(token, api_key, options = {})
|
153
|
-
puts 'WARNING: validate_token_with_app_id is deprecated. Use validate_with_app_access() instead.'
|
154
|
-
validate_with_app_access(token, api_key, options.merge(enrich_user_data: false))
|
155
|
-
end
|
156
|
-
|
157
|
-
# @deprecated Use validate() instead
|
158
|
-
def validate_token_enhanced(token, api_key = nil, options = {})
|
159
|
-
puts 'WARNING: validate_token_enhanced is deprecated. Use validate() instead.'
|
160
|
-
result = validate(token, options.merge(api_key: api_key, enrich_user_data: false))
|
161
|
-
{
|
162
|
-
valid: result[:valid],
|
163
|
-
payload: result[:payload],
|
164
|
-
sub: result[:sub],
|
165
|
-
username: result[:username],
|
166
|
-
token_use: result[:token_use],
|
167
|
-
api_key: result[:api_key],
|
168
|
-
error: result[:error]
|
169
|
-
}
|
170
|
-
end
|
171
|
-
|
172
|
-
# @deprecated Use validate_enriched() instead
|
173
|
-
def validate_token_enriched(token, api_key = nil, options = {})
|
174
|
-
puts 'WARNING: validate_token_enriched is deprecated. Use validate_enriched() instead.'
|
175
|
-
validate_enriched(token, api_key, options)
|
176
|
-
end
|
177
|
-
|
178
|
-
def old_validate_token_enriched(token, api_key = nil, options = {})
|
179
|
-
# First, perform standard token validation
|
180
|
-
basic_result = validate_token_with_api_key(token, api_key, options)
|
181
|
-
|
182
|
-
# If basic validation fails, return early
|
183
|
-
return basic_result unless basic_result[:valid] && basic_result[:payload]
|
184
|
-
|
185
|
-
# If user data retrieval is not enabled, return basic result
|
186
|
-
return basic_result unless @config.enable_user_data_retrieval && @user_data_service
|
187
|
-
|
188
|
-
# Extract user ID from the token
|
189
|
-
user_id = basic_result[:payload]['sub']
|
190
|
-
unless user_id
|
191
|
-
puts 'Token does not contain sub claim, cannot retrieve user data'
|
192
|
-
return basic_result
|
193
|
-
end
|
194
|
-
|
195
|
-
begin
|
196
|
-
# Get comprehensive user data from Redis
|
197
|
-
user_data = @user_data_service.get_comprehensive_user_data(user_id)
|
198
|
-
|
199
|
-
# Add user data to the result
|
200
|
-
enriched_result = basic_result.dup
|
201
|
-
enriched_result[:user_permissions] = user_data['permissions']
|
202
|
-
enriched_result[:user_organizations] = user_data['organizations']
|
203
|
-
enriched_result[:applications] = user_data['applications']
|
204
|
-
|
205
|
-
enriched_result
|
206
|
-
rescue StandardError => e
|
207
|
-
ErrorUtils.log_error(e, 'User data retrieval failed')
|
208
|
-
# Return basic result even if user data retrieval fails
|
209
|
-
basic_result
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
134
|
def validate_access_token(token)
|
214
135
|
result = validate_token(token)
|
215
136
|
|
@@ -96,6 +96,25 @@ module JwtAuthCognito
|
|
96
96
|
Digest::SHA256.hexdigest(token)[0, 16]
|
97
97
|
end
|
98
98
|
|
99
|
+
def get(key)
|
100
|
+
connect_redis
|
101
|
+
@redis.get(key)
|
102
|
+
rescue Redis::BaseError => e
|
103
|
+
raise BlacklistError, "Failed to get key '#{key}': #{e.message}"
|
104
|
+
end
|
105
|
+
|
106
|
+
def set(key, value, ttl = nil)
|
107
|
+
connect_redis
|
108
|
+
if ttl
|
109
|
+
@redis.setex(key, ttl, value)
|
110
|
+
else
|
111
|
+
@redis.set(key, value)
|
112
|
+
end
|
113
|
+
true
|
114
|
+
rescue Redis::BaseError => e
|
115
|
+
raise BlacklistError, "Failed to set key '#{key}': #{e.message}"
|
116
|
+
end
|
117
|
+
|
99
118
|
private
|
100
119
|
|
101
120
|
def connect_redis
|
@@ -177,18 +196,18 @@ module JwtAuthCognito
|
|
177
196
|
end
|
178
197
|
|
179
198
|
def load_ca_certificate
|
180
|
-
# Priority order for certificate loading (
|
181
|
-
# 1. SSM Parameter Store (
|
182
|
-
# 2. Local file system
|
183
|
-
# 3. Environment variable
|
199
|
+
# Priority order for certificate loading (auth-service compatibility):
|
200
|
+
# 1. SSM Parameter Store (using standard variables)
|
201
|
+
# 2. Local file system fallback
|
202
|
+
# 3. Environment variable fallback
|
184
203
|
|
185
|
-
# 1. Try SSM Parameter Store first (
|
186
|
-
if @config.
|
204
|
+
# 1. Try SSM Parameter Store first (auth-service compatibility)
|
205
|
+
if @config.redis_ca_cert_path && @config.redis_ca_cert_name
|
187
206
|
begin
|
188
207
|
puts '🔍 Loading CA certificate from SSM...'
|
189
208
|
return JwtAuthCognito::SSMService.get_ca_certificate(
|
190
|
-
@config.
|
191
|
-
@config.
|
209
|
+
@config.redis_ca_cert_path,
|
210
|
+
@config.redis_ca_cert_name
|
192
211
|
)
|
193
212
|
rescue StandardError => e
|
194
213
|
puts "⚠️ Failed to load certificate from SSM: #{e.message}"
|
@@ -196,12 +215,14 @@ module JwtAuthCognito
|
|
196
215
|
end
|
197
216
|
end
|
198
217
|
|
199
|
-
# 2.
|
218
|
+
# 2. If SSM failed, try as local file system path
|
200
219
|
if @config.redis_ca_cert_path && @config.redis_ca_cert_name
|
201
220
|
ca_cert_file = File.join(@config.redis_ca_cert_path, @config.redis_ca_cert_name)
|
202
221
|
if File.exist?(ca_cert_file)
|
203
222
|
puts "📁 Loading CA certificate from file system: #{ca_cert_file}"
|
204
223
|
return File.read(ca_cert_file)
|
224
|
+
else
|
225
|
+
puts "⚠️ Local file not found: #{ca_cert_file}"
|
205
226
|
end
|
206
227
|
end
|
207
228
|
|
@@ -14,12 +14,28 @@ module JwtAuthCognito
|
|
14
14
|
@client = nil
|
15
15
|
@certificate_cache = {}
|
16
16
|
|
17
|
-
# Initialize the SSM client
|
17
|
+
# Initialize the SSM client with comprehensive AWS configuration
|
18
18
|
def self.get_client
|
19
19
|
@client ||= begin
|
20
20
|
require 'aws-sdk-ssm'
|
21
|
-
|
22
|
-
|
21
|
+
|
22
|
+
client_config = {
|
23
|
+
region: ENV['AWS_REGION'] || ENV['AWS_DEFAULT_REGION'] || 'us-east-1'
|
24
|
+
}
|
25
|
+
|
26
|
+
# Add credentials if provided
|
27
|
+
if ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY']
|
28
|
+
client_config[:credentials] = Aws::Credentials.new(
|
29
|
+
ENV['AWS_ACCESS_KEY_ID'],
|
30
|
+
ENV['AWS_SECRET_ACCESS_KEY'],
|
31
|
+
ENV.fetch('AWS_SESSION_TOKEN', nil)
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Add endpoint if provided (for custom endpoints)
|
36
|
+
client_config[:endpoint] = ENV['AWS_SSM_ENDPOINT'] if ENV['AWS_SSM_ENDPOINT']
|
37
|
+
|
38
|
+
Aws::SSM::Client.new(client_config)
|
23
39
|
end
|
24
40
|
rescue LoadError
|
25
41
|
raise ConfigurationError,
|
@@ -38,7 +54,12 @@ module JwtAuthCognito
|
|
38
54
|
end
|
39
55
|
|
40
56
|
begin
|
57
|
+
region = ENV['AWS_REGION'] || ENV['AWS_DEFAULT_REGION'] || 'us-east-1'
|
58
|
+
has_credentials = !(ENV.fetch('AWS_ACCESS_KEY_ID', nil) && ENV.fetch('AWS_SECRET_ACCESS_KEY', nil)).nil?
|
59
|
+
|
41
60
|
puts "📡 Getting certificate from Parameter Store: #{full_path}"
|
61
|
+
puts "🌍 AWS Region: #{region}"
|
62
|
+
puts "🔑 Credentials configured: #{has_credentials ? 'Yes' : 'No (using IAM role/profile)'}"
|
42
63
|
|
43
64
|
client = get_client
|
44
65
|
response = client.get_parameter({
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jwt_auth_cognito
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Optimal
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-09-
|
11
|
+
date: 2025-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-ssm
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: openssl
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 2.1.0
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 2.1.0
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: redis
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,7 +210,6 @@ metadata:
|
|
224
210
|
changelog_uri: https://github.com/theoptimal/jwt-auth-cognito/blob/main/CHANGELOG.md
|
225
211
|
documentation_uri: https://www.rubydoc.info/gems/jwt_auth_cognito
|
226
212
|
bug_tracker_uri: https://github.com/theoptimal/jwt-auth-cognito/issues
|
227
|
-
rubygems_mfa_required: 'true'
|
228
213
|
post_install_message:
|
229
214
|
rdoc_options:
|
230
215
|
- "--charset=UTF-8"
|