Reglas de Firewall VPC con Cuenta de Servicio como Destino

Guía para aplicar reglas de firewall de entrada basadas en cuentas de servicio en Google Cloud, con implementación, pruebas y limpieza; optimiza seguridad e identidad en workloads cloud native.

14 sept 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Introducción: Las reglas de firewall de entrada con destino en una cuenta de servicio permiten aplicar políticas de red a todas las máquinas virtuales que ejecutan una cuenta de servicio específica independientemente de etiquetas o nombres. Este enfoque es ideal cuando se gestiona el acceso en función de la identidad del workload en lugar de etiquetas estáticas, y encaja muy bien en entornos cloud nativos donde los workloads heredan automáticamente identidades.

Paso 1 Concepto clave: Al elegir Target equal Service Account se crea una regla de ingreso que afecta a todas las VM que usan esa cuenta de servicio. Es una forma basada en identidad que facilita la gestión centralizada y reduce la fragilidad de las reglas que dependen solo de tags o nombres.

Paso 2 Crear la instancia VM y script de arranque: Prepare un script de inicio que instale nginx y configure una página simple que muestre hostname e IP. En la VM se ejecutan comandos como span>#!/bin/bash apt update apt install -y nginx apt install -y telnet systemctl enable nginx chown -R www-data:www-data /var/www/html y se crea un index html con información de la VM. Cree la VM en una subred personalizada con un comando como gcloud compute instances create myvm3-service-accounts --zone=us-central1-a --machine-type=e2-micro --network-interface=subnet=mysubnet1 --metadata-from-file=startup-script=nginx-webserver.sh. Verifique la instancia con gcloud compute instances list.

Pruebas iniciales: Antes de crear la regla de firewall intente conectar a puerto 80 usando telnet EXTERNAL_IP 80 o curl EXTERNAL_IP. Debería fallar si no existe una regla de ingreso permitiendo el puerto 80 para esa VM.

Paso 3 Crear la regla de ingreso basada en cuenta de servicio: Desde la consola VPC o usando gcloud, cree una regla con Target equals Specified service account y como Target service account seleccione la cuenta de Compute Engine correspondiente. Configure Source 0.0.0.0/0 y protocolos TCP puerto 80. En consola: VPC Networks > vpc-custom > FIREWALLS > ADD FIREWALL RULE. En gcloud puede ejecutar un comando equivalente para crear la regla especificando --target-service-accounts y --allow tcp:80.

Paso 4 Comprobar acceso: Tras crear la regla pruebe de nuevo con telnet EXTERNAL_IP 80 y curl EXTERNAL_IP y abra en navegador https://EXTERNAL_IP. Si la VM ejecuta la cuenta de servicio que coincide con la regla, la aplicación desplegada será accesible por el puerto 80.

Paso 5 Limpieza: Elimine la regla de firewall y la VM cuando ya no las necesite con comandos como gcloud compute firewall-rules delete fw-ingress-80-service-accounts y gcloud compute instances delete myvm3-service-accounts --zone=us-central1-a --delete-disks=all.

Aprendizajes clave: Target all instances es rápido pero amplio y menos seguro. Target tags es útil para agrupar por función. Target service accounts es identity based y más dinámico, recomendado para arquitecturas cloud native donde los workloads heredan identidades. Este método facilita auditoría, políticas basadas en identidad y escalabilidad operativa.

Sobre Q2BSTUDIO: Q2BSTUDIO es una empresa de desarrollo de software y aplicaciones a medida especializada en soluciones personalizadas, inteligencia artificial, ciberseguridad y servicios cloud. Ofrecemos desarrollo de aplicaciones a medida y software a medida que se integran con arquitecturas seguras y automatizadas. Si busca crear soluciones empresariales a la medida puede conocer nuestros servicios de desarrollo en aplicaciones a medida y explorar proyectos de inteligencia artificial para empresas en inteligencia artificial.

Palabras clave y servicios: aplicaciones a medida, software a medida, inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios inteligencia de negocio, ia para empresas, agentes IA, power bi. También ofrecemos pruebas de seguridad y pentesting, integración con plataformas cloud y consultoría en Business Intelligence y Power BI para mejorar la observabilidad y toma de decisiones.

Contacto y siguiente paso: Si necesita diseñar políticas de red basadas en identidad, integrar cuentas de servicio en su estrategia de seguridad o desarrollar soluciones seguras y escalables en la nube, Q2BSTUDIO puede ayudar con consultoría, desarrollo e implementación. Nuestros servicios abarcan desde ciberseguridad y pentesting hasta automatización de procesos e inteligencia de negocio, todo pensado para acelerar su transformación digital.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.