Browse Source

fix jelly files

Allan Barcelos 1 year ago
parent
commit
b56437563c

+ 1 - 1
.github/CODEOWNERS

@@ -1 +1 @@
-* @jenkinsci/mfa-google-auth-plugin-developers
+* @jenkinsci/mfa-totp-plugin-developers

+ 80 - 102
README.md

@@ -1,151 +1,129 @@
-# MFA Google Auth Plugin
+# 🔐 MFA TOTP Authentication Plugin for Jenkins
 
-[![Jenkins Plugin](https://img.shields.io/jenkins/plugin/v/mfa-google-auth.svg)](https://plugins.jenkins.io/mfa-google-auth)
-[![Jenkins Plugin Installs](https://img.shields.io/jenkins/plugin/i/mfa-google-auth.svg?color=blue)](https://plugins.jenkins.io/mfa-google-auth)
+[![Jenkins Plugin](https://img.shields.io/jenkins/plugin/v/mfa-totp-plugin.svg)](https://plugins.jenkins.io/mfa-google-auth)
+[![Jenkins Plugin Installs](https://img.shields.io/jenkins/plugin/i/mfa-totp-plugin.svg?color=blue)](https://plugins.jenkins.io/mfa-google-auth)
+[![Build Status](https://ci.jenkins.io/buildStatus/icon?job=Plugins/mfa-totp-plugin/master)](https://ci.jenkins.io/job/Plugins/job/mfa-totp-plugin/)
 [![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
 
-A Jenkins plugin that enforces **multi‑factor authentication (MFA)** using **TOTP Authenticator**.
-This plugin adds an additional layer of security by requiring users to provide a time‑based one‑time password (TOTP) after entering their username and password.
+Enhance your Jenkins security with Time-based One-Time Password (TOTP) multi-factor authentication. This plugin integrates seamlessly with authenticator apps like Google Authenticator to provide an additional layer of protection beyond passwords.
 
----
-
-## ✨ Features
-
-✅ Enforces MFA for Jenkins users
-
-✅ Integrates with [Google Authenticator](https://github.com/google/google-authenticator)
-
-✅ Configurable enforcement policies
-
-✅ Easy to set up and manage through Jenkins UI
-
----
+## 🌟 Key Features
 
-## 📦 Installation
+- **🔒 Stronger Security**: Mandates MFA for all Jenkins access
+- **📱 TOTP Support**: Works with Google/Microsoft Authenticator and other TOTP apps
+- **⚙️ Flexible Configuration**: Global enforcement or per-user setup
+- **⏱️ Session Management**: Configurable authentication duration
+- **🤖 CI/CD Friendly**: Optional API token exclusion for automation
 
-1. Build the plugin:
+## 📥 Installation
 
-   ```bash
-   mvn clean package
-   ```
+### Prerequisites
+- Jenkins 2.387.3 or later
+- Java 17+
 
-   After a successful build, you will find the `.hpi` file in the `target/` directory.
+### Installation Methods
 
-2. Upload to Jenkins:
+#### Method 1: Jenkins Plugin Manager
+1. Navigate to **Manage Jenkins** → **Plugins** → **Available plugins**
+2. Search for "MFA TOTP Plugin"
+3. Install and restart Jenkins
 
-   * Go to **Manage Jenkins → Manage Plugins → Advanced**
-   * Use the **Upload Plugin** section to upload the `mfa-google-auth.hpi`.
-
-3. Restart Jenkins if required.
-
----
-
-## 🔧 Configuration
-
-1. In Jenkins, go to **Manage Jenkins → Configure Global Security**.
-2. Enable **MFA Google Auth Plugin** under the security realm or configure it as instructed in your environment.
-3. Each user should scan the generated QR code with Google Authenticator (or a compatible TOTP app) and enter their verification code.
-
----
+#### Method 2: Manual Installation
+```bash
+# Build the plugin
+mvn clean package
 
-# 🔐 MFA TOTP Plugin - Global Configuration Guide
+# Then upload the .hpi file from target/ directory via:
+# Manage Jenkins → Plugins → Advanced → Upload Plugin
+```
 
-## 🛠 System Configuration
+## 🛠 Configuration Guide
 
-### 1. Enable Global MFA Enforcement
-1. Navigate to **"Manage Jenkins"** > **"Configure System"**
-2. Scroll to the **"Global MFA Settings"** section
-3. Check **"Enforce MFA for all users"**:
-   - ✅ Enabled: All users must set up MFA on next login
-   - ❌ Disabled: MFA remains optional per user
+### Global Security Settings
+1. Go to **Manage Jenkins** → **Configure Global Security**
+2. Under *Security Realm*, enable **MFA TOTP Authentication**
+3. Configure enforcement policies:
+   - Enforce for all users
+   - Session duration (default: 8 hours)
+   - API token exclusion
 
-### 2. Advanced Settings
-| Setting | Description | Recommended Value |
-|---------|-------------|-------------------|
-| **Exclude API tokens** | Allows API access without MFA | Enable for CI/CD pipelines | 
-| **MFA session duration (minutes)** | Time before re-verification | 480 (8 hours) |
-| **Force reconfiguration** | Require periodic MFA reset | 90 days |
+### User Setup Flow
+1. Users access their account settings
+2. Scan the QR code with an authenticator app
+3. Verify initial code
+4. Save backup codes securely
 
-![Settings screenshot](path/to/screenshot.png)
+![Configuration Screenshot](docs/images/config-screen.png)
 
-## 👤 User Experience Flow
-When global MFA is enabled:
-1. At first login, users will be redirected to setup
-2. They must:
-   - Scan QR code with authenticator app
-   - Verify with a valid TOTP code
+## ⚙️ Advanced Configuration
 
-## ⚙️ API Configuration (JSON)
+### JSON API Configuration
 ```bash
-curl -X POST http://jenkins/configure \
+curl -X POST http://your-jenkins/configure \
   -u admin:api_token \
   -H "Content-Type: application/json" \
   -d '{
     "mfa": {
       "enforceForAllUsers": true,
-      "excludeApiTokens": true,
+      "excludeApiTokens": false,
       "sessionDuration": 480
     }
   }'
 ```
 
-## 🔐 Security Best Practices
+### Security Best Practices
 1. **For Admins**:
-   - Enable global MFA for all privileged accounts
-   - Maintain one emergency break-glass account
+   - Enable MFA for all administrative accounts
+   - Maintain emergency break-glass credentials
+   - Regularly review MFA configurations
 
 2. **For Users**:
-   - Use trusted authenticator apps (Google/Microsoft Authenticator)
+   - Use trusted authenticator apps
    - Store recovery codes securely
+   - Rotate MFA secrets annually
 
 ## 🚨 Troubleshooting
-### Issue: User cannot configure MFA
-**Solution**:
-1. Verify Jenkins server time synchronization
-2. Check logs at `/var/log/jenkins/mfa.log`
-
-### Issue: API returns 403 errors
-**Solution**:
-1. Enable "Exclude API tokens" in global settings  
-2. Generate new API tokens after MFA activation
-
----
-
-## 📌 Requirements
 
-* **Jenkins Core**: `2.479.3` or newer
-* **Java**: 17 or newer
-* A TOTP app such as [Google Authenticator](https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2).
+| Issue | Solution |
+|-------|----------|
+| Invalid TOTP codes | Verify server time synchronization |
+| API access denied | Enable "Exclude API tokens" in settings |
+| QR code not appearing | Check browser console for JavaScript errors |
 
----
+For additional help, check the plugin logs at:
+`$JENKINS_HOME/logs/mfa-totp-plugin.log`
 
 ## 🛠 Development
 
-This plugin is built with the [Jenkins Plugin Parent POM](https://github.com/jenkinsci/plugin-pom).
-
-To work on the plugin locally:
-
+### Build Environment
 ```bash
-# Build and run tests
-mvn clean verify
-
-# Run Jenkins with the plugin
-mvn hpi:run
+mvn clean verify       # Run full build with tests
+mvn hpi:run            # Launch test Jenkins instance
 ```
 
-Then open Jenkins at [http://localhost:8080/jenkins/](http://localhost:8080/jenkins/).
+### Contribution Guidelines
+1. Fork the repository
+2. Create feature branches (`feature/your-feature`)
+3. Submit pull requests with clear descriptions
 
+## 🔒 Security Policy
 
----
-
-## Security
+Vulnerabilities should be reported following [Jenkins security guidelines](https://www.jenkins.io/security/#reporting-vulnerabilities). Please do not disclose security issues publicly.
 
-Security vulnerabilities should be reported following the [Jenkins vulnerability reporting guidelines](https://www.jenkins.io/security/#reporting-vulnerabilities). 
+## 📜 License
 
-Please do not report security issues through GitHub issues or public discussions.
+Licensed under [MIT License](LICENSE). 
 
 ---
 
-## 📜 License
-
-This project is licensed under the [MIT License](LICENSE).
+✉️ **Contact**: For support questions, please use the [Jenkins community forums](https://community.jenkins.io/).
+
+This version improves:
+1. Better visual hierarchy with emoji categorization
+2. More detailed configuration instructions
+3. Clearer tables for troubleshooting
+4. Improved contribution guidelines
+5. Better separation of admin vs user instructions
+6. More professional tone throughout
+7. Added missing sections (contact, development)
+8. Consistent formatting

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
   </parent>
 
   <groupId>io.jenkins.plugins</groupId>
-  <artifactId>mfa-totp-plugin</artifactId>
+  <artifactId>mfa-totp</artifactId>
   <version>${revision}${changelist}</version>
   <packaging>hpi</packaging>
 

+ 0 - 1
src/main/java/io/jenkins/plugins/MfaFilter.java

@@ -22,7 +22,6 @@ import jakarta.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-
 import jenkins.model.GlobalConfiguration;
 import jenkins.model.Jenkins;
 

+ 1 - 1
src/main/java/io/jenkins/plugins/MfaFilterRegister.java

@@ -1,5 +1,5 @@
 /*
- * Project: MFA Google Auth Plugin
+ * Project: MFA TOTP Auth Plugin
  *
  * Class: MfaFilterRegister
  *

+ 1 - 0
src/main/resources/Messages.properties

@@ -1,3 +1,4 @@
+# /src/main/resources/Messages.properties
 # Core MFA Properties
 MfaUserProperty.displayName=MFA (TOTP Authenticator)
 

+ 1 - 0
src/main/resources/Messages_pt_BR.properties

@@ -1,3 +1,4 @@
+# /src/main/resources/Messages_pt_BR.properties
 # Core MFA Properties
 MfaUserProperty.displayName=MFA (Autenticador TOTP)
 

+ 1 - 0
src/main/resources/index.jelly

@@ -1,3 +1,4 @@
+<!-- /src/main/resources/index.jelly -->
 <?jelly escape-by-default='true'?>
 <div>
   Adds TOTP-based Multi-Factor Authentication (MFA/2FA) to Jenkins using TOTP Authenticator.

+ 1 - 0
src/main/resources/io/jenkins/plugins/Messages.properties

@@ -1,3 +1,4 @@
+# /src/main/resources/io/jenkins/plugins/Messages.properties
 # Core MFA Properties
 MfaUserProperty.displayName=MFA (TOTP Authenticator)
 

+ 1 - 0
src/main/resources/io/jenkins/plugins/Messages_pt_BR.properties

@@ -1,3 +1,4 @@
+# /src/main/resources/io/jenkins/plugins/Messages_pt_BR.properties
 # Core MFA Properties
 MfaUserProperty.displayName=MFA (Autenticador TOTP)
 

+ 1 - 0
src/main/resources/io/jenkins/plugins/MfaGlobalConfig/config.jelly

@@ -1,3 +1,4 @@
+<!-- /src/main/resources/io/jenkins/plugins/MfaGlobalConfig/config.jelly -->
 <?jelly escape-by-default='true'?>
 <j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
     <f:section title="Global MFA Settings">

+ 1 - 0
src/main/resources/io/jenkins/plugins/MfaGlobalConfig/config.properties

@@ -1,3 +1,4 @@
+# /src/main/resources/io/jenkins/plugins/MfaGlobalConfig/config.properties
 enforceMfaForAllUsers.displayName=Enforce MFA for all users
 enforceMfaForAllUsers.description=When enabled, all users will be required to set up and use MFA.
 

+ 3 - 1
src/main/resources/io/jenkins/plugins/MfaUserProperty/MfaUserProperty.properties

@@ -1 +1,3 @@
-adjuncts.io.jenkins.plugins.MfaUserProperty.script=/io/jenkins/plugins/MfaUserProperty/script.js
+# /src/main/resources/io/jenkins/plugins/MfaUserProperty/MfaUserProperty.properties
+adjuncts.io.jenkins.plugins.MfaUserProperty.script=/io/jenkins/plugins/MfaUserProperty/script.js
+adjuncts.io.jenkins.plugins.MfaUserProperty.style=/io/jenkins/plugins/MfaUserProperty/style.css

+ 6 - 10
src/main/resources/io/jenkins/plugins/MfaUserProperty/config.jelly

@@ -1,15 +1,19 @@
+<!-- /src/main/resources/io/jenkins/plugins/MfaUserProperty/config.jelly -->
 <?jelly escape-by-default='true'?>
 <j:jelly xmlns:j="jelly:core" 
          xmlns:f="/lib/form" 
          xmlns:l="/lib/layout"
-         xmlns:st="jelly:stapler"> <!-- Adicione esta linha -->
+         xmlns:st="jelly:stapler">
+
+  <st:adjunct includes="io.jenkins.plugins.MfaUserProperty.style"/>
+  <st:adjunct includes="io.jenkins.plugins.MfaUserProperty.script"/>
 
   <f:entry title="${%MfaUserProperty.enable.label}" field="mfaEnabled">
     <f:checkbox id="mfaEnabledCheckbox" />
   </f:entry>
 
   <j:if test="${!instance.mfaEnabled}">
-    <div id="mfaSetupContainer" style="display:none; margin-top:10px;">
+    <div id="mfaSetupContainer" class="hidden">
       <f:entry title="${%MfaUserProperty.qrCode.label}">
         <img id="qrCodeImage" alt="${%MfaUserProperty.qrCode.alt}" />
       </f:entry>
@@ -21,12 +25,4 @@
       <input type="hidden" name="_.secretKey" />
     </div>
   </j:if>
-
-  <st:adjunct includes="io.jenkins.plugins.MfaUserProperty.script" />
-  
-  <script>
-    document.addEventListener('DOMContentLoaded', function() {
-      initMfaToggle();
-    });
-  </script>
 </j:jelly>

+ 1 - 0
src/main/resources/io/jenkins/plugins/MfaUserProperty/config.properties

@@ -1,3 +1,4 @@
+# /src/main/resources/io/jenkins/plugins/MfaUserProperty/config.properties
 # Core MFA Properties
 MfaUserProperty.displayName=MFA (TOTP Authenticator)
 

+ 11 - 7
src/main/resources/io/jenkins/plugins/MfaUserProperty/script.js

@@ -1,3 +1,8 @@
+// /src/main/resources/io/jenkins/plugins/MfaUserProperty/script.js
+document.addEventListener('DOMContentLoaded', function() {
+    initMfaToggle();
+});
+
 function initMfaToggle() {
     const checkbox = document.getElementById('mfaEnabledCheckbox');
     const container = document.getElementById('mfaSetupContainer');
@@ -6,14 +11,15 @@ function initMfaToggle() {
 
     function showOrHideMfaSetup() {
         if (checkbox.checked) {
-            container.style.display = 'block';
+            container.classList.remove('hidden');
+            container.classList.add('visible');
 
             if (!qrImage.src) {
                 fetch(window.rootURL + '/mfa-totp/generateSecret')
                     .then(resp => resp.json())
                     .then(data => {
                         qrImage.src = window.rootURL + '/mfa-totp/qrcode?secret=' + 
-                                      encodeURIComponent(data.secret);
+                                    encodeURIComponent(data.secret);
                         secretInput.value = data.secret;
                     })
                     .catch(err => {
@@ -21,7 +27,8 @@ function initMfaToggle() {
                     });
             }
         } else {
-            container.style.display = 'none';
+            container.classList.remove('visible');
+            container.classList.add('hidden');
             qrImage.src = '';
             secretInput.value = '';
         }
@@ -32,7 +39,4 @@ function initMfaToggle() {
     if (checkbox.checked) {
         showOrHideMfaSetup();
     }
-}
-
-// Exporta a função para ser chamada pelo jelly
-window.initMfaToggle = initMfaToggle;
+}

+ 14 - 0
src/main/resources/io/jenkins/plugins/MfaUserProperty/style.css

@@ -0,0 +1,14 @@
+/* /src/main/resources/io/jenkins/plugins/MfaUserProperty/style.css */
+.hidden {
+    display: none;
+}
+
+.visible {
+    display: block;
+    margin-top: 10px;
+}
+
+.error-message {
+    color: red;
+    font-weight: bold;
+}

+ 5 - 4
src/main/resources/io/jenkins/plugins/MfaVerifyAction/index.jelly

@@ -1,15 +1,16 @@
+<!-- /src/main/resources/io/jenkins/plugins/MfaVerifyAction/index.jelly -->
 <?jelly escape-by-default='true'?>
 <j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:f="/lib/form">
   <l:layout title="MFA Verification">
     <l:main-panel>
       <h1>MFA Verify</h1>
       <j:if test="${request.getParameter('error') != null}">
-        <div style="color:red; font-weight:bold;">
-          Invalid code. Try again.
+        <div class="error-message">
+          ${%MfaUserProperty.totpCode.invalid}
         </div>
       </j:if>
       <form method="post" action="${rootURL}/mfa-verify/verify">
-        <f:entry title="Code">
+        <f:entry title="${%MfaUserProperty.verificationCode.label}">
           <f:textbox name="totpCode" />
         </f:entry>
         <f:entry>
@@ -18,4 +19,4 @@
       </form>
     </l:main-panel>
   </l:layout>
-</j:jelly>
+</j:jelly>