-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,097 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Copyright (c) 2024. Some Engineering | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
import logging | ||
from datetime import datetime, timedelta | ||
|
||
from fastapi_users_db_sqlalchemy.generics import GUID | ||
from fixcloudutils.asyncio.periodic import Periodic | ||
from fixcloudutils.service import Service | ||
from fixcloudutils.util import utc | ||
from sqlalchemy import String, Integer, select, Index, and_, func, text | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
|
||
from fixbackend.auth.models.orm import User | ||
from fixbackend.base_model import Base | ||
from fixbackend.ids import UserId | ||
from fixbackend.notification.email import email_messages | ||
from fixbackend.notification.email.email_sender import EmailSender | ||
from fixbackend.sqlalechemy_extensions import UTCDateTime | ||
from fixbackend.types import AsyncSessionMaker | ||
from fixbackend.utils import uid | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class ScheduledEmailEntity(Base): | ||
__tablename__ = "scheduled_email" | ||
id: Mapped[GUID] = mapped_column(GUID, primary_key=True) | ||
kind: Mapped[str] = mapped_column(String(64), nullable=False) | ||
after: Mapped[int] = mapped_column(Integer, nullable=False) | ||
|
||
|
||
class ScheduledEmailSentEntity(Base): | ||
__tablename__ = "scheduled_email_sent" | ||
id: Mapped[GUID] = mapped_column(GUID, primary_key=True) | ||
user_id: Mapped[UserId] = mapped_column(GUID, nullable=False) | ||
kind: Mapped[str] = mapped_column(String(64), nullable=False) | ||
at: Mapped[datetime] = mapped_column(UTCDateTime, nullable=False) | ||
|
||
user_kind_index = Index("user_kind_index", "user_id", "kind") | ||
|
||
|
||
class ScheduledEmailSender(Service): | ||
def __init__(self, email_sender: EmailSender, session_maker: AsyncSessionMaker) -> None: | ||
self.email_sender = email_sender | ||
self.session_maker = session_maker | ||
self.periodic = Periodic("scheduled_email_sender", self._send_emails, timedelta(seconds=600)) | ||
|
||
async def start(self) -> None: | ||
await self.periodic.start() | ||
|
||
async def stop(self) -> None: | ||
await self.periodic.stop() | ||
|
||
async def _send_emails(self) -> None: | ||
async with self.session_maker() as session: | ||
stmt = ( | ||
select(User, ScheduledEmailEntity) | ||
.select_from( | ||
# This uses a literal TRUE to simulate a cross join | ||
User.__table__.join(ScheduledEmailEntity.__table__, text("true")) | ||
) | ||
.outerjoin( | ||
ScheduledEmailSentEntity, | ||
and_( | ||
User.id == ScheduledEmailSentEntity.user_id, # type: ignore | ||
ScheduledEmailEntity.kind == ScheduledEmailSentEntity.kind, | ||
), | ||
) | ||
.where( | ||
and_( | ||
text("user.created_at + INTERVAL scheduled_email.after SECOND") < func.now(), | ||
ScheduledEmailSentEntity.id.is_(None), | ||
) | ||
) | ||
) | ||
result = await session.execute(stmt) | ||
user: User | ||
to_send: ScheduledEmailEntity | ||
for user, to_send in result.unique().all(): | ||
subject = email_messages.render(f"{to_send.kind}.subject").strip() | ||
txt = email_messages.render(f"{to_send.kind}.txt") | ||
html = email_messages.render(f"{to_send.kind}.html") | ||
log.info(f"Sending email to {user.email} with subject {subject} and body {html}") | ||
await self.email_sender.send_email(to=user.email, subject=subject, text=txt, html=html) | ||
# mark this kind of email as sent | ||
session.add(ScheduledEmailSentEntity(id=uid(), user_id=user.id, kind=to_send.kind, at=utc())) | ||
await session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
|
||
<h1> Day 1: Effortless Search, Powerful Insights </h1> | ||
|
||
<p> | ||
Imagine having the ability to pinpoint any resource in your cloud environment within seconds. | ||
With Fix, that's not just possible; it's your new reality. | ||
Our search functionality is designed to streamline your workflows, enhance security, and ensure you're always just a | ||
few keystrokes away from finding exactly what you need. | ||
</p> | ||
|
||
<p> | ||
This tutorial assumes that you connected at least one cloud account with Fix. If not already happened, please visit | ||
the setup cloud accounts page in fix and connect your accounts. | ||
</p> | ||
|
||
<h2>Filter by Origin</h2> | ||
<p> | ||
Log into your Fix account and navigate to the Inventory. | ||
Here, you find dropdowns for the most common filters. | ||
</p> | ||
<p> | ||
<img src="https://cdn.some.engineering/fix/assets/101/day1/filter-overview.png" width="530" alt="Filer Overview"/> | ||
</p> | ||
<p> | ||
Filter resources by cloud, account, region or zone is straightforward. | ||
You can also narrow down the list of resources by a specific tag. | ||
</p> | ||
|
||
<h2>Filter by Security Severity</h2> | ||
<p> | ||
Fix analyzes all your resources against different security benchmarks and compliance frameworks. | ||
Fix marks all security vulnerabilities on the resource. | ||
The severity filter now allows you to filter for resources that have vulnerabilities of a specific severity. | ||
</p> | ||
|
||
<p> | ||
<img src="https://cdn.some.engineering/fix/assets/101/day1/severity-filter.png" width="280" alt="Severity Filter"/> | ||
</p> | ||
|
||
<h2>Filter by Kind</h2> | ||
<p> | ||
The Kinds filter allows you to filter resources of a specific service, e.g. Lambda Functions or IAM roles. This is | ||
the goto filter if you want to narrow down specific resources by specific property filters. | ||
</p> | ||
<p> | ||
<img src="https://cdn.some.engineering/fix/assets/101/day1/kinds-filter.png" width="280" alt="Kinds Filter"/> | ||
</p> | ||
|
||
<h2>Filter by Property</h2> | ||
<p> | ||
Every resource kind has its own set of properties. Fix allows you to filter resources by any property. Press the + | ||
button. Based on the selected kind of resource, you now see all possible properties. | ||
</p> | ||
<p> | ||
<img src="https://cdn.some.engineering/fix/assets/101/day1/property-filter.png" width="250" alt="Property Filter"/> | ||
</p> | ||
|
||
<p> | ||
Once the property is selected, you can define the operation and filter value. The value dropdown shows all possible | ||
values that exist for the selected property in the current search configuration. | ||
</p> | ||
|
||
<p> | ||
<img src="https://cdn.some.engineering/fix/assets/101/day1/property-value.png" width="480" alt="Property Value"/> | ||
</p> | ||
|
||
<p> | ||
We're Here to Help | ||
If any steps feel unclear, or if you encounter any bumps along the road, our team is standing by. | ||
</p> | ||
<p> | ||
Contact us at <a href="mailto:[email protected]">[email protected]</a> or ping us on <a | ||
href="https://discord.gg/fixsecurity">Discord</a>. | ||
</p> | ||
|
||
Happy searching,<br/> | ||
The Fix Team | ||
|
||
|
||
|
||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix 101 Day 1: Effortless Search, Powerful Insights |
Oops, something went wrong.